From 487be5ef1be2cbc2d064cf50618fb96c729b409c Mon Sep 17 00:00:00 2001 From: David Kagan Date: Mon, 3 Apr 2023 09:56:36 -0400 Subject: [PATCH] More attempts to implement api.DeleteShard attempting to understand how shards are related to indexes, fields, and views. --- api.go | 29 +++++++++++++++++++++-------- api_directive.go | 4 ++++ dbshard.go | 5 +++++ index.go | 10 ++++++---- txfactory.go | 4 ++++ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/api.go b/api.go index b8aa8e817..d0e27c798 100644 --- a/api.go +++ b/api.go @@ -724,6 +724,11 @@ func (api *API) ImportRoaring(ctx context.Context, indexName, fieldName string, } } +func (api *API) DeletePartition(ctx context.Context, indexName string, partition int) error { // not sure what else is needed here for arguments + // will probably need an index.go implementation? + return nil +} + // DeleteField removes the named field from the named index. If the index is not // found, an error is returned. If the field is not found, it is ignored and no // action is taken. @@ -761,7 +766,9 @@ func (api *API) DeleteField(ctx context.Context, indexName string, fieldName str } // DeleteShard deletes a given shard in an index. -func (api *API) DeleteShard(_ context.Context, indexName string, shardID uint64) error { +// This is me taking a stab at implementing this logic, currently +// a no-op implementation - DK +func (api *API) DeleteShard(ctx context.Context, indexName string, shardID uint64) error { if err := api.validate(apiDeleteShard); err != nil { return errors.Wrap(err, "validating api method") } @@ -772,13 +779,19 @@ func (api *API) DeleteShard(_ context.Context, indexName string, shardID uint64) return newNotFoundError(ErrIndexNotFound, indexName) } - // Get views of shards - // --> maybe can use InMemSharder() from disco? - sharder := disco.NewInMemSharder() - ctx := context.Background() - // sharder.Shards(ctx, idx,) <-- need a field name - // ??? sv := idx.fieldView2shard().removeField() - // ??? maybe just use the api.DeleteField() method? + // Get a DBShard. + dbs, err := api.holder.Txf().dbPerShard.GetDBShard(indexName, shardID, idx) + if err != nil { + return errors.Wrapf(err, "GetDBShard") + } + + // Delete shard + // currently a no-op implementation --> working on logic + if err := idx.DeleteShard(ctx, idx.Name(), dbs.Shard); err != nil { + return errors.Wrapf(err, "deleting shard") + } + + // Since this is serverless, don't need to send to all nodes. return nil } diff --git a/api_directive.go b/api_directive.go index 5e78f6059..543d9c5c6 100644 --- a/api_directive.go +++ b/api_directive.go @@ -343,6 +343,9 @@ func (api *API) pushJobsTableKeys(ctx context.Context, jobs chan<- directiveJobT api.Holder().Index(string(tkey)).TranslateStore(int(partition)) //.Delete(records *roaring.Bitmap) // this implementation is going to be much more difficult + + //implement this via no-op + api.DeletePartition(ctx, string(qtid.Name), int(partition)) } } @@ -439,6 +442,7 @@ func (api *API) pushJobsFieldKeys(ctx context.Context, jobs chan<- directiveJobT for _, field := range fields { api.serverlessStorage.RemoveFieldKeyResource(qtid, field) + // Attempt at implementing deletion from disk -- DK // deleting field from disk err := api.DeleteField(ctx, string(tkey), string(field)) if err != nil { diff --git a/dbshard.go b/dbshard.go index 95a6d7788..00af16206 100644 --- a/dbshard.go +++ b/dbshard.go @@ -331,6 +331,11 @@ func (per *DBPerShard) DeleteFieldFromStore(index, field, fieldPath string) (err return err } +// DeleteShardFromStore is currently a no-op implementation +func (per *DBPerShard) DeleteShardFromStore(index string, shardID uint64) error { + return nil +} + func (per *DBPerShard) DeleteFragment(index, field, view string, shard uint64, frag *fragment) error { idx := per.txf.holder.Index(index) diff --git a/index.go b/index.go index ea7c94a62..9dd5e103e 100644 --- a/index.go +++ b/index.go @@ -1016,14 +1016,16 @@ func (i *Index) DeleteField(name string) error { return i.translationSyncer.Reset() } -func (i *Index) DeleteShard(shardName string) error { - i.mu.Lock() - defer i.mu.Unlock() +// DeleteShard removes a shard in an index. +// This is currently a no-op implementation +func (i *Index) DeleteShard(ctx context.Context, indexName string, shardID uint64) error { - // Confirm shard exists. // Delete shard // --> need to make schemator DeleteShard too? + // --> --> shards and partitions aren't part of schema? // ??? + + i.holder.txf.DeleteShardFromStore(indexName, shardID) // profit return nil diff --git a/txfactory.go b/txfactory.go index c801c2ed3..5a468eae4 100644 --- a/txfactory.go +++ b/txfactory.go @@ -479,6 +479,10 @@ func (f *TxFactory) DeleteFieldFromStore(index, field, fieldPath string) (err er return f.dbPerShard.DeleteFieldFromStore(index, field, fieldPath) } +func (f *TxFactory) DeleteShardFromStore(index string, shardID uint64) error { + return f.dbPerShard.DeleteShardFromStore(index, shardID) +} + func (f *TxFactory) DeleteFragmentFromStore( index, field, view string, shard uint64, frag *fragment, ) (err error) {