From 4bff8b23cb3a78ebbfeffa9f3da0218dd470a3f7 Mon Sep 17 00:00:00 2001 From: David Kagan Date: Thu, 30 Mar 2023 14:26:11 -0400 Subject: [PATCH] WIP on DeleteShard, currently still nop --- api.go | 17 +++++++++++++++++ api_directive.go | 9 ++++----- index.go | 13 +++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/api.go b/api.go index b7c155db8..35a8ae6ad 100644 --- a/api.go +++ b/api.go @@ -760,7 +760,22 @@ func (api *API) DeleteField(ctx context.Context, indexName string, fieldName str return nil } +// DeleteShard deletes a given shard in an index. func (api *API) DeleteShard(_ context.Context, indexName string, shardID uint64) error { + if err := api.validate(apiDeleteShard); err != nil { + return errors.Wrap(err, "validating api method") + } + + // Find index. + idx := api.holder.Index(indexName) + if idx == nil { + return newNotFoundError(ErrIndexNotFound, indexName) + } + + // Get views of shards + // ??? sv := idx.fieldView2shard().removeField() + // ??? maybe just use the api.DeleteField() method? + return nil } @@ -3187,6 +3202,7 @@ const ( apiCreateField apiCreateIndex apiDeleteField + apiDeleteShard apiDeleteAvailableShard apiDeleteIndex apiDeleteView @@ -3257,6 +3273,7 @@ var methodsNormal = map[apiMethod]struct{}{ apiCreateField: {}, apiCreateIndex: {}, apiDeleteField: {}, + apiDeleteShard: {}, apiDeleteAvailableShard: {}, apiDeleteIndex: {}, apiDeleteView: {}, diff --git a/api_directive.go b/api_directive.go index 0d917558d..5e78f6059 100644 --- a/api_directive.go +++ b/api_directive.go @@ -341,7 +341,8 @@ func (api *API) pushJobsTableKeys(ctx context.Context, jobs chan<- directiveJobT //maybe start with shards, since multiple shards belong to a partition api.Holder().Index(string(tkey)).TranslateStore(int(partition)) //.Delete(records *roaring.Bitmap) - // maybe need to do this since it's local disk? os.RemoveAll(pathname) maybe partition path? + + // this implementation is going to be much more difficult } } @@ -433,14 +434,12 @@ func (api *API) pushJobsFieldKeys(ctx context.Context, jobs chan<- directiveJobT fieldComp := newFieldsComparer(fromD.TranslateFieldsMap(), toD.TranslateFieldsMap()) // Remove any field keys which are no longer assigned to this worker. - // TODO(tlt): currently, this is just removing the file lock on the - // resource; it's not actually removing the resource from the local - // computer. We should do that. for tkey, fields := range fieldComp.removed() { qtid := tkey.QualifiedTableID() for _, field := range fields { api.serverlessStorage.RemoveFieldKeyResource(qtid, field) + // deleting field from disk err := api.DeleteField(ctx, string(tkey), string(field)) if err != nil { errors.Wrapf(err, "error deleting field") @@ -541,7 +540,7 @@ func (api *API) pushJobsShards(ctx context.Context, jobs chan<- directiveJobType for _, shard := range shards { partition := dax.PartitionNum(disco.ShardToShardPartition(string(tkey), uint64(shard), disco.DefaultPartitionN)) api.serverlessStorage.RemoveShardResource(qtid, partition, shard) - + //this is a noop implementation of DeleteShard for now err := api.DeleteShard(ctx, string(tkey), uint64(shard)) if err != nil { diff --git a/index.go b/index.go index 5887d2a41..ea7c94a62 100644 --- a/index.go +++ b/index.go @@ -1016,6 +1016,19 @@ 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() + + // Confirm shard exists. + // Delete shard + // --> need to make schemator DeleteShard too? + // ??? + // profit + + return nil +} + // SetTranslatePartitions sets the cached value: translatePartitions. // // There's already logic in api_directive.go which creates a new index with