More attempts to implement api.DeleteShard

attempting to understand how shards are related to indexes, fields, and views.
This commit is contained in:
David Kagan 2023-04-03 09:56:36 -04:00
parent 01f069aec7
commit 487be5ef1b
5 changed files with 40 additions and 12 deletions

29
api.go
View file

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

View file

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

View file

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

View file

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

View file

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