-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TTL + table store #811
TTL + table store #811
Conversation
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
@@ -5,14 +5,17 @@ import ( | |||
"github.com/Layr-Labs/eigenda/common/kvstore" | |||
"github.com/syndtr/goleveldb/leveldb/iterator" | |||
"github.com/syndtr/goleveldb/leveldb/util" | |||
"time" | |||
) | |||
|
|||
var _ kvstore.Table = &tableView{} | |||
|
|||
// tableView allows data in a table to be accessed as if it were a Store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table view tries to appear like a store, by wrapping two stores...these are getting too complicated and won't be simple to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually wrapping two stores, this class has access to two different interfaces on the same store. This constructor isn't publicly exported, so it's impossible for an end user to instantiate this class with two different stores.
That being said, in order to simplify this method, I've modified the function signature to make things easier to read.
The reason why this class needed access to the parent TableStore
class was for the methods Shutdown()
, Destroy()
, and NewBatch()
. Instead of passing in the whole TableStore
, we can just pass in lambdas for the functionality needed by the table view.
func newTableView(
base kvstore.Store,
name string,
prefix uint32,
shutdown func() error,
destroy func() error,
batchBuilder func() kvstore.TableStoreBatch) kvstore.Table {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specific issue here is that tableView
doesn't appear to be Store, it's trying to be a Table
(e.g. the TTL related interfaces do not exist for Store)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface Table
currently extends the interface Store
. A user can interact with a table as if it were a regular Store
object.
type Table interface {
Store
Name() string
TableKey(key []byte) TableKey
PutWithTTL(key []byte, value []byte, ttl time.Duration) error
PutWithExpiration(key []byte, value []byte, expiryTime time.Time) error
NewTTLBatch() TTLStoreBatch
}
common/kvstore/ttl_store.go
Outdated
// parallel or to modify a batch while the store is being modified, it is not thread safe to concurrently | ||
// modify the same batch. | ||
type TTLStoreBatch TTLBatch[[]byte] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you are trying to merge ttl into tablestore, can these be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I've merged the TTLStore
interface into the Table
interface.
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
@@ -375,22 +371,46 @@ func loadNamespaceTable(namespaceTable kvstore.Table) (map[uint32]string, error) | |||
return tableIDMap, nil | |||
} | |||
|
|||
// CreateTable creates a new table with the given name. If a table with the given name already exists, | |||
// this method becomes a no-op. Returns ErrTableLimitExceeded if the maximum number of tables has been reached. | |||
// CreateTable creates a new table with the given name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: createTable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
// time-to-live (TTL) or expiration times. Although it is thread safe to modify different batches in | ||
// parallel or to modify a batch while the store is being modified, it is not thread safe to concurrently | ||
// modify the same batch. | ||
type TTLBatch[K any] interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks this is not needed?
- if it's a
Table
, there isTableBatch
, operating on the raw keys - if it's a
TableStore
, there isTableStoreBatch
, operating on the namespaced keys
And the ttl related interfaces are always there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The batch APIs have now been simplified so that they don't have generics. Are there additional simplifications you'd like to see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we still need two batch interfaces if we want to support batches that can set different TTLs for operations within the same batch. The core reason is that the basic Store
API does not have a concept of a TTL, meaning we need a batch interface that doesn't have TTLs.
@@ -5,14 +5,17 @@ import ( | |||
"github.com/Layr-Labs/eigenda/common/kvstore" | |||
"github.com/syndtr/goleveldb/leveldb/iterator" | |||
"github.com/syndtr/goleveldb/leveldb/util" | |||
"time" | |||
) | |||
|
|||
var _ kvstore.Table = &tableView{} | |||
|
|||
// tableView allows data in a table to be accessed as if it were a Store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specific issue here is that tableView
doesn't appear to be Store, it's trying to be a Table
(e.g. the TTL related interfaces do not exist for Store)
base kvstore.Store | ||
// name is the name of the table. | ||
name string | ||
// prefix is the prefix for all keys in the table. | ||
prefix uint32 | ||
// shutdown is a function that shuts down the table store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the following 3 interfaces make sense to be here? They are all operating as the TableStore, not Table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core problem is that Table
implements Store
, which means it needs to implement methods like Shutdown()
. If you'd like to change this, I can think of the following options:
- make methods like
Shutdown()
into no-ops - make methods like
Shutdown()
return an error - split the
Store
interface into several interfaces:- the interface called
Store
will just have the methodsGet()
,Put()
,Delete()
, etc. - There will be an interface called
DBStore
(or similar) that implementsStore
and adds methods such asShutdown()
- Things such as
LevelDBStore
will implementDBStore
, whileTable
will only implementStore
.Table
will no longer have odd methods such asShutdown()
.
- the interface called
- Replace
Table
s with key builders (I don't think you like this option, mentioning it for completeness 😜)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to either option if it makes sense. I think the "weirdness" in APIs may indicate we could structure them better (like the case here). Do you prefer using key builder? Option 3 seems complicated to me.
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
Signed-off-by: Cody Littley <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm mostly
common/kvstore/key.go
Outdated
|
||
// Key represents a key in a TableStore. Each key is scoped to a specific table. | ||
type Key interface { | ||
// AsString interprets the key as a string and returns it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are a lot of types, can we start with what we know we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed all of the methods except for the ones that deal with bytes. The other methods were not strictly necessary, just syntactic sugar.
Signed-off-by: Cody Littley <[email protected]>
Why are these changes needed?
This PR unifies the concepts of a "table store" and a "ttl store". Table stores now support TTLs, and there is no stand alone ttl store.
Checks