Skip to content

Commit eea04eb

Browse files
authored
MB-71131: Support file writer callbacks for trained index (#2379)
- implement the `fileWriterIDs` and `removeFileWriterIDs` APIs which fetch and remove the file writer IDs/keys corresponding to the trained segment. - refactor the request handling + ack mechanism of the trainLoop() - update the destination index's bolt with the trained sample count, for consistent stats
1 parent bc8495d commit eea04eb

3 files changed

Lines changed: 326 additions & 103 deletions

File tree

index/scorch/scorch.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ type trainer interface {
123123
// trainer specific file transfer operations
124124
copyFileLOCKED(file string, d index.IndexDirectory) error
125125
updateBolt(snapshotsBucket *util.BoltBucketImpl, key []byte, value []byte) error
126+
127+
dropFileWriterIDs(ids map[string]struct{}) error
128+
fileWriterIDsInUse() (map[string]struct{}, error)
126129
}
127130

128131
type ScorchErrorType string
@@ -1116,10 +1119,12 @@ func (s *Scorch) SetPathInBolt(key []byte, value []byte) error {
11161119
return err
11171120
}
11181121

1119-
// currently this is specific to trained index file update
1120-
err = s.trainer.updateBolt(snapshotsBucket, key, value)
1121-
if err != nil {
1122-
return err
1122+
if s.trainer != nil {
1123+
// currently this is specific to trained index file update
1124+
err = s.trainer.updateBolt(snapshotsBucket, key, value)
1125+
if err != nil {
1126+
return err
1127+
}
11231128
}
11241129

11251130
err = tx.Commit()
@@ -1332,6 +1337,16 @@ func (s *Scorch) FileWriterIDsInUse() (map[string]struct{}, error) {
13321337
}
13331338
}
13341339

1340+
if s.trainer != nil {
1341+
trainerKeys, err := s.trainer.fileWriterIDsInUse()
1342+
if err != nil {
1343+
return nil, err
1344+
}
1345+
for k, _ := range trainerKeys {
1346+
keyMap[k] = struct{}{}
1347+
}
1348+
}
1349+
13351350
boltKeys, err := s.boltFileWriterIDsInUse()
13361351
if err != nil {
13371352
return nil, err
@@ -1354,6 +1369,13 @@ func (s *Scorch) DropFileWriterIDs(ids map[string]struct{}) error {
13541369
return err
13551370
}
13561371

1372+
if s.trainer != nil {
1373+
err := s.trainer.dropFileWriterIDs(ids)
1374+
if err != nil {
1375+
return err
1376+
}
1377+
}
1378+
13571379
s.rootLock.Lock()
13581380
// create a done channel to ensure success of merge
13591381
ctx := context.Background()

index/scorch/train_noop.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ func (t *noopTrainer) copyFileLOCKED(file string, d index.IndexDirectory) error
5353
func (t *noopTrainer) updateBolt(snapshotsBucket *util.BoltBucketImpl, key []byte, value []byte) error {
5454
return nil
5555
}
56+
57+
func (t *noopTrainer) dropFileWriterIDs(ids map[string]struct{}) error {
58+
return nil
59+
}
60+
61+
func (t *noopTrainer) fileWriterIDsInUse() (map[string]struct{}, error) {
62+
return nil, nil
63+
}

0 commit comments

Comments
 (0)