Skip to content

Commit c7a94a6

Browse files
committed
refactor file transfer
1 parent 3bfb59e commit c7a94a6

2 files changed

Lines changed: 0 additions & 116 deletions

File tree

index/scorch/scorch.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
package scorch
1616

1717
import (
18-
"bytes"
1918
"encoding/json"
2019
"fmt"
21-
"io"
2220
"os"
2321
"path/filepath"
2422
"strings"
@@ -1212,88 +1210,6 @@ func (s *Scorch) CopyReader() index.CopyReader {
12121210
return rv
12131211
}
12141212

1215-
func (s *Scorch) UpdateFileInBolt(key []byte, value []byte) error {
1216-
tx, err := s.rootBolt.Begin(true)
1217-
if err != nil {
1218-
return err
1219-
}
1220-
defer func() {
1221-
if err != nil {
1222-
_ = tx.Rollback()
1223-
}
1224-
}()
1225-
1226-
snapshotsBucket, err := tx.CreateBucketIfNotExists(util.BoltSnapshotsBucket)
1227-
if err != nil {
1228-
return err
1229-
}
1230-
1231-
// currently this is specific to centroid index file update
1232-
if bytes.Equal(key, util.BoltCentroidIndexKey) {
1233-
// todo: guard against duplicate updates
1234-
centroidBucket, err := snapshotsBucket.CreateBucketIfNotExists(util.BoltCentroidIndexKey)
1235-
if err != nil {
1236-
return err
1237-
}
1238-
if centroidBucket == nil {
1239-
return fmt.Errorf("centroid bucket not found")
1240-
}
1241-
existingValue := centroidBucket.Get(util.BoltPathKey)
1242-
if existingValue != nil {
1243-
return fmt.Errorf("key already exists %v %v", s.path, string(existingValue))
1244-
}
1245-
1246-
err = centroidBucket.Put(util.BoltPathKey, value)
1247-
if err != nil {
1248-
return err
1249-
}
1250-
}
1251-
1252-
err = tx.Commit()
1253-
if err != nil {
1254-
return err
1255-
}
1256-
1257-
err = s.rootBolt.Sync()
1258-
if err != nil {
1259-
return err
1260-
}
1261-
1262-
return nil
1263-
}
1264-
1265-
// CopyFile copies a specific file to a destination directory which has an access to a bleve index
1266-
// doing a io.Copy() isn't enough because the file needs to be tracked in bolt file as well
1267-
func (s *Scorch) CopyFile(file string, d index.IndexDirectory) error {
1268-
s.rootLock.Lock()
1269-
defer s.rootLock.Unlock()
1270-
1271-
// this code is currently specific to centroid index file but is future proofed for other files
1272-
// to be updated in the dest's bolt
1273-
if strings.HasSuffix(file, "centroid_index") {
1274-
// centroid index file - this is outside the snapshots domain so the bolt update is different
1275-
err := d.UpdateFileInBolt(util.BoltCentroidIndexKey, []byte(file))
1276-
if err != nil {
1277-
return fmt.Errorf("error updating dest index bolt: %w", err)
1278-
}
1279-
}
1280-
1281-
dest, err := d.GetWriter(filepath.Join("store", file))
1282-
if err != nil {
1283-
return err
1284-
}
1285-
1286-
source, err := os.Open(filepath.Join(s.path, file))
1287-
if err != nil {
1288-
return err
1289-
}
1290-
1291-
defer source.Close()
1292-
defer dest.Close()
1293-
_, err = io.Copy(dest, source)
1294-
return err
1295-
}
1296-
12971213
// external API to fire a scorch event (EventKindIndexStart) externally from bleve
12981214
func (s *Scorch) FireIndexEvent() {
12991215
s.fireEvent(EventKindIndexStart, 0)

index_impl.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,38 +1432,6 @@ func (m *searchHitSorter) Less(i, j int) bool {
14321432
return c < 0
14331433
}
14341434

1435-
func (i *indexImpl) CopyFile(file string, d index.IndexDirectory) (err error) {
1436-
i.mutex.RLock()
1437-
defer i.mutex.RUnlock()
1438-
1439-
if !i.open {
1440-
return ErrorIndexClosed
1441-
}
1442-
1443-
copyIndex, ok := i.i.(index.IndexFileCopyable)
1444-
if !ok {
1445-
return fmt.Errorf("index implementation does not support copy reader")
1446-
}
1447-
1448-
return copyIndex.CopyFile(file, d)
1449-
}
1450-
1451-
func (i *indexImpl) UpdateFileInBolt(key []byte, value []byte) error {
1452-
i.mutex.RLock()
1453-
defer i.mutex.RUnlock()
1454-
1455-
if !i.open {
1456-
return ErrorIndexClosed
1457-
}
1458-
1459-
copyIndex, ok := i.i.(index.IndexFileCopyable)
1460-
if !ok {
1461-
return fmt.Errorf("index implementation does not support file copy")
1462-
}
1463-
1464-
return copyIndex.UpdateFileInBolt(key, value)
1465-
}
1466-
14671435
// CopyTo (index.Directory, filter)
14681436
func (i *indexImpl) CopyTo(d index.Directory) (err error) {
14691437
i.mutex.RLock()

0 commit comments

Comments
 (0)