|
15 | 15 | package scorch |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "bytes" |
19 | 18 | "encoding/json" |
20 | 19 | "fmt" |
21 | | - "io" |
22 | 20 | "os" |
23 | 21 | "path/filepath" |
24 | 22 | "strings" |
@@ -1212,88 +1210,6 @@ func (s *Scorch) CopyReader() index.CopyReader { |
1212 | 1210 | return rv |
1213 | 1211 | } |
1214 | 1212 |
|
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 | | - |
1297 | 1213 | // external API to fire a scorch event (EventKindIndexStart) externally from bleve |
1298 | 1214 | func (s *Scorch) FireIndexEvent() { |
1299 | 1215 | s.fireEvent(EventKindIndexStart, 0) |
|
0 commit comments