WIP on DeleteShard, currently still nop

This commit is contained in:
David Kagan 2023-03-30 14:26:11 -04:00
parent cd020f7827
commit 4bff8b23cb
3 changed files with 34 additions and 5 deletions

17
api.go
View file

@ -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: {},

View file

@ -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 {

View file

@ -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