diff --git a/state/ravendb/proposal.md b/state/ravendb/proposal.md new file mode 100644 index 0000000000..32afcae111 --- /dev/null +++ b/state/ravendb/proposal.md @@ -0,0 +1,17 @@ +# About Raven DB + +[RavenDB](https://ravendb.net/about) is document NoSQL database that supports ACID. +We have over 1000 organizations that use RavenDB from startups to Fortune 500 companies like JetBrains, +Toyota and Verizon just to name a few. + +# Motivation + +We got feature request from some of our clients to implement Dapr State store & IO bindings. +Their project was growing in size, and they started rolling out more and more microservices and wanted to use Dapr. + +We see that supporting RaveDb inside Dapr ecosystem as beneficial to both sides. + +## Technical spec + +RavenDB has several SDK's with [Go SDK](https://github.com/ravendb/ravendb-go-client) one of them. +Link to our official [docs](https://ravendb.net/docs/article-page/6.0/csharp) and [demo](https://demo.ravendb.net/) example in multiple languages. diff --git a/state/ravendb/ravendb.go b/state/ravendb/ravendb.go index ddd68c628f..ca58375b1f 100644 --- a/state/ravendb/ravendb.go +++ b/state/ravendb/ravendb.go @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package mongodb is an implementation of StateStore interface to perform operations on store +// Package ravendb is an implementation of StateStore interface to perform operations on store package ravendb @@ -19,7 +19,6 @@ import ( "context" "crypto/tls" "crypto/x509" - "encoding/json" "errors" "fmt" "github.com/dapr/components-contrib/metadata" @@ -29,6 +28,7 @@ import ( kitmd "github.com/dapr/kit/metadata" jsoniterator "github.com/json-iterator/go" ravendb "github.com/ravendb/ravendb-go-client" + "net/http" "reflect" "strings" "time" @@ -52,9 +52,8 @@ const ( type RavenDB struct { state.BulkStore - documentStore *ravendb.DocumentStore - operationTimeout time.Duration - metadata RavenDBMetadata + documentStore *ravendb.DocumentStore + metadata RavenDBMetadata features []state.Feature logger logger.Logger @@ -95,12 +94,10 @@ func (r *RavenDB) Init(ctx context.Context, metadata state.Metadata) (err error) if err != nil { return err } - - fmt.Println("parsed metadata") //TODO: Operation timeout? store, err := r.getRavenDBStore(ctx) if err != nil { - return fmt.Errorf("error in creating Raven DB Store") + return errors.New("error in creating Raven DB Store") } r.initTTL(store) @@ -118,7 +115,7 @@ func (r *RavenDB) Features() []state.Feature { func (r *RavenDB) Delete(ctx context.Context, req *state.DeleteRequest) error { session, err := r.documentStore.OpenSession("") if err != nil { - return fmt.Errorf("error opening session while deleting") + return errors.New("error opening session while deleting") } defer session.Close() @@ -129,7 +126,7 @@ func (r *RavenDB) Delete(ctx context.Context, req *state.DeleteRequest) error { err = session.SaveChanges() if err != nil { - return fmt.Errorf("error saving changes") + return errors.New("error saving changes") } return nil @@ -193,7 +190,6 @@ func (r *RavenDB) Set(ctx context.Context, req *state.SetRequest) error { err = session.SaveChanges() if err != nil { - fmt.Println("error saving changes:", err) return fmt.Errorf("error saving changes %s", err) } return nil @@ -201,10 +197,10 @@ func (r *RavenDB) Set(ctx context.Context, req *state.SetRequest) error { func (r *RavenDB) Ping(ctx context.Context) error { session, err := r.documentStore.OpenSession("") - defer session.Close() if err != nil { return fmt.Errorf("error opening session while storing data faild with error %s", err) } + defer session.Close() return nil } @@ -216,7 +212,6 @@ func (r *RavenDB) Multi(ctx context.Context, request *state.TransactionalStateRe } defer session.Close() for _, o := range request.Operations { - var err error switch req := o.(type) { case state.SetRequest: err = r.setInternal(ctx, &req, session) @@ -269,11 +264,6 @@ func (r *RavenDB) BulkGet(ctx context.Context, req []state.GetRequest, _ state.B Data: []byte(current.Value), Metadata: make(map[string]string), } - convJson, _ := json.Marshal(convert) - itemJson, _ := json.Marshal(current) - - fmt.Println(string(convJson)) - fmt.Println(string(itemJson)) resp = append(resp, convert) } @@ -309,7 +299,6 @@ func (r *RavenDB) setInternal(ctx context.Context, req *state.SetRequest, sessio // First write wins, we send empty change vector to check if exists err = session.StoreWithChangeVectorAndID(item, "", req.Key) if err != nil { - fmt.Println(err) return fmt.Errorf("error storing data: %s", err) } } else { @@ -322,7 +311,6 @@ func (r *RavenDB) setInternal(ctx context.Context, req *state.SetRequest, sessio } if err != nil { - fmt.Println(err) return fmt.Errorf("error storing data: %s", err) } } @@ -335,7 +323,7 @@ func (r *RavenDB) setInternal(ctx context.Context, req *state.SetRequest, sessio if reqTTL != nil { metaData, err := session.Advanced().GetMetadataFor(item) if err != nil { - return fmt.Errorf("Failed to get metadata for item") + return errors.New("Failed to get metadata for item") } expiry := time.Now().Add(time.Second * time.Duration(*reqTTL)).UTC() iso8601String := expiry.Format("2006-01-02T15:04:05.9999999Z07:00") @@ -419,22 +407,16 @@ func (r *RavenDB) initTTL(store *ravendb.DocumentStore) { } operation, err := ravendb.NewConfigureExpirationOperationWithConfiguration(&configurationExppiration) if err != nil { - fmt.Println("error setting expiration operation") return } - - err = store.Maintenance().Send(operation) - if err != nil { - fmt.Println("error sending command") - } + store.Maintenance().Send(operation) } func (r *RavenDB) setupDatabase(store *ravendb.DocumentStore) { operation := ravendb.NewGetDatabaseRecordOperation(r.metadata.DatabaseName) err := store.Maintenance().Server().Send(operation) - fmt.Println(err) if err == nil { - if operation.Command != nil && operation.Command.RavenCommandBase.StatusCode == 404 { + if operation.Command != nil && operation.Command.RavenCommandBase.StatusCode == http.StatusNotFound { databaseRecord := ravendb.DatabaseRecord{ DatabaseName: r.metadata.DatabaseName, Disabled: false, diff --git a/state/ravendb/ravendb_test.go b/state/ravendb/ravendb_test.go index 45875ffe48..990c25aa1f 100644 --- a/state/ravendb/ravendb_test.go +++ b/state/ravendb/ravendb_test.go @@ -57,7 +57,7 @@ func TestGetRavenDBMetadata(t *testing.T) { require.NoError(t, err) assert.Equal(t, properties[serverURL], metadata.ServerURL) assert.Equal(t, properties[databaseName], metadata.DatabaseName) - assert.Equal(t, false, metadata.EnableTTL) + assert.False(t, metadata.EnableTTL) assert.Equal(t, int64(15), metadata.TTLFrequency) }) diff --git a/tests/certification/go.sum b/tests/certification/go.sum index 1055475a16..5ef3b4a6ea 100644 --- a/tests/certification/go.sum +++ b/tests/certification/go.sum @@ -455,6 +455,7 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= @@ -734,6 +735,7 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= @@ -933,6 +935,7 @@ github.com/kitex-contrib/monitor-prometheus v0.0.0-20210817080809-024dd7bd51e1/g github.com/kitex-contrib/obs-opentelemetry v0.0.0-20220601144657-c60210e3c928/go.mod h1:VvMzPMfgL7iUG92eVZGuRybGVMKzuSrsfMvHHpL7/Ac= github.com/kitex-contrib/obs-opentelemetry/logging/logrus v0.0.0-20220601144657-c60210e3c928/go.mod h1:Eml/0Z+CqgGIPf9JXzLGu+N9NJoy2x5pqypN+hmKArE= github.com/kitex-contrib/tracer-opentracing v0.0.2/go.mod h1:mprt5pxqywFQxlHb7ugfiMdKbABTLI9YrBYs9WmlK5Q= +github.com/kjk/httplogproxy v0.0.0-20190214011443-6743ea9a2d3d/go.mod h1:kkVhzcC9maw+0jdT2UfGGikRmobjydsBiD6ElexuTLk= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= @@ -955,6 +958,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= @@ -1222,6 +1226,8 @@ github.com/puzpuzpuz/xsync/v3 v3.0.0 h1:QwUcmah+dZZxy6va/QSU26M6O6Q422afP9jO8Jln github.com/puzpuzpuz/xsync/v3 v3.0.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0h1hA= github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc= +github.com/ravendb/ravendb-go-client v0.0.0-20240723121956-2b87f37fe427 h1:hOnThDlsq0e4M7Sl3A3MnMlazYJsNuuDDqywa5mI7wQ= +github.com/ravendb/ravendb-go-client v0.0.0-20240723121956-2b87f37fe427/go.mod h1:Zhu1DOotWGZcjom6CZH+8mJ2AD3fOx0QjVIrbpMxN04= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=