Skip to content

Commit

Permalink
Convert default backend from "inmem" to "keyvalue" (#1475)
Browse files Browse the repository at this point in the history
* Copy existing inmem backend to keyvalue. Test with Artifact and IsOccurrence.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Update all of keyvalue backend to from old inmem to new kv interface.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Add changes from commit 165897d to keyvalue.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Add changes from commit fb58ab3 to keyvalue.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Remove inmem.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

---------

Signed-off-by: Jeff Mendoza <jlm@jlm.name>
  • Loading branch information
jeffmendoza committed Nov 13, 2023
1 parent 5521770 commit 030cf7f
Show file tree
Hide file tree
Showing 70 changed files with 6,651 additions and 6,525 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -75,7 +75,7 @@ The following are [GraphQL backends](pkg/assembler/backends) that are implemente
3. Optimized: The backend has gone through a level of optimization to help improve performance.

The enumerated backends are:
- [inmem (supported, complete, optimized)](https://github.com/guacsec/guac/tree/main/pkg/assembler/backends/inmem): a non-persistent in-memory backend that doesn't require any additional infrastructure. Also acts as a conformance backend for API implementations. We recommend starting with this if you're just starting with GUAC!
- [keyvalue (supported, complete, optimized)](https://github.com/guacsec/guac/tree/main/pkg/assembler/backends/keyvalue): a non-persistent in-memory backend that doesn't require any additional infrastructure. Also acts as a conformance backend for API implementations. We recommend starting with this if you're just starting with GUAC!
- [arangoDB (supported, incomplete, optimized)](https://github.com/guacsec/guac/tree/main/pkg/assembler/backends/arangodb): a persistent backend based on [ArangoDB](https://arangodb.com/)
- [ent (supported, incomplete)](https://github.com/guacsec/guac/tree/main/pkg/assembler/backends/ent): a persistent backend based on [ent](https://entgo.io/) that can run on various SQL backends such as [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/) and [SQLite](https://www.sqlite.org/index.html).
- [neo4j/openCypher (unsupported, incomplete)](https://github.com/guacsec/guac/tree/main/pkg/assembler/backends/neo4j): a persistent backend based on [neo4j](https://neo4j.com/) and [openCypher](https://opencypher.org/). This backend should work with any database that supported openCypher queries.
Expand Down
2 changes: 1 addition & 1 deletion cmd/README.md
Expand Up @@ -32,7 +32,7 @@ services:

- what it does: runs a GraphQL server
- options:
- backend: inmem, neo4j, arango, ent, or future DB
- backend: keyvalue, neo4j, arango, ent, or future DB
- backend-specific options: neo4j connection options
- playground / debug: also start playground

Expand Down
8 changes: 4 additions & 4 deletions cmd/guacgql/cmd/server.go
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/99designs/gqlgen/graphql/playground"
"github.com/guacsec/guac/pkg/assembler/backends"
"github.com/guacsec/guac/pkg/assembler/backends/arangodb"
_ "github.com/guacsec/guac/pkg/assembler/backends/inmem"
_ "github.com/guacsec/guac/pkg/assembler/backends/keyvalue"
"github.com/guacsec/guac/pkg/assembler/backends/neo4j"
"github.com/guacsec/guac/pkg/assembler/backends/neptune"
"github.com/guacsec/guac/pkg/assembler/graphql/generated"
Expand All @@ -43,9 +43,9 @@ import (
const (
arango = "arango"
neo4js = "neo4j"
inmems = "inmem"
ent = "ent"
neptunes = "neptune"
keyvalue = "keyvalue"
)

type optsFunc func() backends.BackendArgs
Expand All @@ -58,8 +58,8 @@ func init() {
}
getOpts[arango] = getArango
getOpts[neo4js] = getNeo4j
getOpts[inmems] = getInMem
getOpts[neptunes] = getNeptune
getOpts[keyvalue] = getKeyValue
}

func startServer(cmd *cobra.Command) {
Expand Down Expand Up @@ -171,7 +171,7 @@ func getNeo4j() backends.BackendArgs {
}
}

func getInMem() backends.BackendArgs {
func getKeyValue() backends.BackendArgs {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions container_files/guac/guac.yaml
Expand Up @@ -6,7 +6,7 @@ csub-addr: guac-collectsub:2782
csub-listen-port: 2782

# graphql
gql-backend: inmem
gql-backend: keyvalue
gql-listen-port: 8080
gql-debug: true
gql-addr: http://guac-graphql:8080/query
Expand All @@ -17,4 +17,4 @@ use-csub: true

# certifier polling
poll: true
interval: 5m
interval: 5m
2 changes: 1 addition & 1 deletion guac.yaml
Expand Up @@ -25,7 +25,7 @@ csub-addr: localhost:2782
csub-listen-port: 2782

# GQL setup
gql-backend: inmem
gql-backend: keyvalue
gql-listen-port: 8080
gql-debug: true
gql-addr: http://localhost:8080/query
Expand Down
51 changes: 51 additions & 0 deletions internal/testing/stablememmap/stablememmap.go
@@ -0,0 +1,51 @@
//
// Copyright 2023 The GUAC Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stablememmap

import (
"context"
"slices"

"github.com/guacsec/guac/pkg/assembler/kv"
"github.com/guacsec/guac/pkg/assembler/kv/memmap"
)

type Store struct {
mm kv.Store
}

func GetStore() kv.Store {
return &Store{
mm: memmap.GetStore(),
}
}

func (s *Store) Get(ctx context.Context, c, k string, v any) error {
return s.mm.Get(ctx, c, k, v)
}

func (s *Store) Set(ctx context.Context, c, k string, v any) error {
return s.mm.Set(ctx, c, k, v)
}

func (s *Store) Keys(ctx context.Context, c string) ([]string, error) {
keys, err := s.mm.Keys(ctx, c)
if err != nil {
return nil, err
}
slices.Sort(keys)
return keys, nil
}

0 comments on commit 030cf7f

Please sign in to comment.