Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion any_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (t AnyTable) queryIndex(txn ReadTxn, index string, key string) (tableIndexR
return itxn, rawKey, err
}

func (t AnyTable) Changes(txn WriteTxn) (anyChangeIterator, error) {
func (t AnyTable) Changes(txn WriteTxn) (AnyChangeIterator, error) {
return t.Meta.anyChanges(txn)
}

Expand Down
29 changes: 5 additions & 24 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
package statedb

import (
"context"
"fmt"
"iter"
"log/slog"
"math/rand"
"slices"
"testing"
Expand All @@ -16,9 +14,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cilium/hive"
"github.com/cilium/hive/cell"
"github.com/cilium/hive/hivetest"
"github.com/cilium/statedb/index"
"github.com/cilium/statedb/part"
)
Expand Down Expand Up @@ -603,26 +598,12 @@ var (
func BenchmarkDB_PropagationDelay(b *testing.B) {
const batchSize = 10

var (
db *DB
table1 RWTable[*testObject]
table2 RWTable[*testObject2]
)

h := hive.New(
Cell, // DB
cell.Invoke(func(db_ *DB) error {
db = db_
table1 = MustNewTable(db, "test", idIndex)
table2 = MustNewTable(db, "test2", id2Index)
return nil
}),
)

log := hivetest.Logger(b, hivetest.LogLevel(slog.LevelError))
require.NoError(b, h.Start(log, context.TODO()))
db := New()
table1 := MustNewTable(db, "test", idIndex)
table2 := MustNewTable(db, "test2", id2Index)
require.NoError(b, db.Start())
b.Cleanup(func() {
assert.NoError(b, h.Stop(log, context.TODO()))
assert.NoError(b, db.Stop())
})

b.ResetTimer()
Expand Down
76 changes: 5 additions & 71 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ package statedb

import (
"bytes"
"context"
"encoding/json"
"errors"
"expvar"
"fmt"
"iter"
"log/slog"
"net/netip"
"runtime"
"slices"
Expand All @@ -24,12 +22,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/cilium/hive"
"github.com/cilium/hive/cell"
"github.com/cilium/hive/hivetest"
"github.com/cilium/statedb/index"
"github.com/cilium/statedb/part"
"github.com/cilium/stream"
)

// Amount of time to wait for the watch channel to close in tests
Expand Down Expand Up @@ -149,28 +143,12 @@ func newTestDB(t testing.TB, secondaryIndexers ...Indexer[*testObject]) (*DB, RW
}

func newTestDBWithMetrics(t testing.TB, metrics Metrics, secondaryIndexers ...Indexer[*testObject]) (*DB, RWTable[*testObject]) {
var (
db *DB
table RWTable[*testObject]
)

h := hive.New(
cell.Provide(func() Metrics { return metrics }),
Cell, // DB
cell.Invoke(func(db_ *DB) {
table = newTestObjectTable(t, db_, "test", secondaryIndexers...)

// Use a short GC interval.
db_.setGCRateLimitInterval(50 * time.Millisecond)

db = db_
}),
)

log := hivetest.Logger(t, hivetest.LogLevel(slog.LevelError))
require.NoError(t, h.Start(log, context.TODO()))
db := New(WithMetrics(metrics))
table := newTestObjectTable(t, db, "test", secondaryIndexers...)
db.setGCRateLimitInterval(50 * time.Millisecond)
require.NoError(t, db.Start())
t.Cleanup(func() {
assert.NoError(t, h.Stop(log, context.TODO()))
assert.NoError(t, db.Stop())
})
return db, table
}
Expand Down Expand Up @@ -617,50 +595,6 @@ func TestDB_Changes(t *testing.T) {
wtxn.Abort()
}

func TestDB_Observable(t *testing.T) {
t.Parallel()

db, table, _ := newTestDB(t)
ctx, cancel := context.WithCancel(context.Background())
events := stream.ToChannel(ctx, Observable(db, table))

txn := db.WriteTxn(table)
_, hadOld, err := table.Insert(txn, &testObject{ID: uint64(1)})
require.False(t, hadOld, "Expected no prior object")
require.NoError(t, err, "Insert failed")
_, hadOld, err = table.Insert(txn, &testObject{ID: uint64(2)})
require.False(t, hadOld, "Expected no prior object")
require.NoError(t, err, "Insert failed")
txn.Commit()

event := <-events
require.False(t, event.Deleted, "expected insert")
require.Equal(t, uint64(1), event.Object.ID)
event = <-events
require.False(t, event.Deleted, "expected insert")
require.Equal(t, uint64(2), event.Object.ID)

txn = db.WriteTxn(table)
_, hadOld, err = table.Delete(txn, &testObject{ID: uint64(1)})
require.True(t, hadOld, "Expected that object was deleted")
require.NoError(t, err, "Delete failed")
_, hadOld, err = table.Delete(txn, &testObject{ID: uint64(2)})
require.True(t, hadOld, "Expected that object was deleted")
require.NoError(t, err, "Delete failed")
txn.Commit()

event = <-events
require.True(t, event.Deleted, "expected delete")
require.Equal(t, uint64(1), event.Object.ID)
event = <-events
require.True(t, event.Deleted, "expected delete")
require.Equal(t, uint64(2), event.Object.ID)

cancel()
ev, ok := <-events
require.False(t, ok, "expected channel to close, got event: %+v", ev)
}

func TestDB_NumObjects(t *testing.T) {
t.Parallel()

Expand Down
33 changes: 6 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module github.com/cilium/statedb
go 1.25

require (
github.com/cilium/hive v1.0.0
github.com/cilium/stream v0.0.0-20240209152734-a0792b51812d
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/cilium/statedb/part v0.0.0
github.com/stretchr/testify v1.8.4
go.uber.org/goleak v1.3.0
go.yaml.in/yaml/v3 v3.0.3
Expand All @@ -16,28 +12,11 @@ require (

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/cilium/statedb/part => ./part
78 changes: 4 additions & 74 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,93 +1,23 @@
github.com/cilium/hive v1.0.0 h1:HEPvIFBCgAWOBclSVHoDXGpRB5SPgzMXdB54BOrITKE=
github.com/cilium/hive v1.0.0/go.mod h1:4/8FBMcTjVdkrNNWaB7t3QqaU4kZDJLJ1leKVP9GjEI=
github.com/cilium/stream v0.0.0-20240209152734-a0792b51812d h1:p6MgATaKEB9o7iAsk9rlzXNDMNCeKPAkx4Y8f+Zq8X8=
github.com/cilium/stream v0.0.0-20240209152734-a0792b51812d/go.mod h1:3VLiLgs8wfjirkuYqos4t0IBPQ+sXtf3tFkChLm6ARM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
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/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE=
go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 8 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
go 1.25

use (
.
./hive
./part
./reconciler
)
14 changes: 7 additions & 7 deletions cell.go → hive/cell.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package statedb
package hive

import (
"github.com/cilium/hive/cell"
"github.com/cilium/statedb"
)

// This module provides an in-memory database built on top of immutable radix trees
// As the database is based on an immutable data structure, the objects inserted into
// the database MUST NOT be mutated, but rather copied first!
// Cell is a [cell.Module] that provides a [*statedb.DB] instance and
// registers the statedb script commands for use in hive script tests.
var Cell = cell.Module(
"statedb",
"In-memory transactional database",
Expand All @@ -24,11 +24,11 @@ type params struct {
cell.In

Lifecycle cell.Lifecycle
Metrics Metrics `optional:"true"`
Metrics statedb.Metrics `optional:"true"`
}

func newHiveDB(p params) *DB {
db := New(WithMetrics(p.Metrics))
func newHiveDB(p params) *statedb.DB {
db := statedb.New(statedb.WithMetrics(p.Metrics))
p.Lifecycle.Append(
cell.Hook{
OnStart: func(cell.HookContext) error {
Expand Down
9 changes: 5 additions & 4 deletions derive.go → hive/derive.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package statedb
package hive

import (
"context"

"github.com/cilium/hive/cell"
"github.com/cilium/hive/job"
"github.com/cilium/statedb"
)

type DeriveResult int
Expand All @@ -24,9 +25,9 @@ type DeriveParams[In, Out any] struct {

Lifecycle cell.Lifecycle
JobGroup job.Group
DB *DB
InTable Table[In]
OutTable RWTable[Out]
DB *statedb.DB
InTable statedb.Table[In]
OutTable statedb.RWTable[Out]
}

// Derive constructs and registers a job to transform objects from the input table to the
Expand Down
Loading
Loading