Browse Source

separate transaction

pull/7178/head
chrislu 2 weeks ago
parent
commit
8d54fded4b
  1. 9
      weed/filer/foundationdb/foundationdb_store.go

9
weed/filer/foundationdb/foundationdb_store.go

@ -62,7 +62,7 @@ const transactionKey contextKey = "fdb_transaction"
// Helper functions for context-scoped transactions // Helper functions for context-scoped transactions
func (store *FoundationDBStore) getTransactionFromContext(ctx context.Context) (fdb.Transaction, bool) { func (store *FoundationDBStore) getTransactionFromContext(ctx context.Context) (fdb.Transaction, bool) {
if tx, ok := ctx.Value(transactionKey).(fdb.Transaction); ok {
if tx, ok := ctx.Value(transactionKey).(fdb.Transaction); ok && tx != nil {
return tx, true return tx, true
} }
var emptyTx fdb.Transaction var emptyTx fdb.Transaction
@ -303,13 +303,16 @@ func (store *FoundationDBStore) DeleteFolderChildren(ctx context.Context, fullpa
func (store *FoundationDBStore) deleteFolderChildrenInBatches(ctx context.Context, fullpath util.FullPath) error { func (store *FoundationDBStore) deleteFolderChildrenInBatches(ctx context.Context, fullpath util.FullPath) error {
const BATCH_SIZE = 100 // Delete up to 100 entries per transaction const BATCH_SIZE = 100 // Delete up to 100 entries per transaction
// Ensure listing and recursion run outside of any ambient transaction
ctxNoTxn := context.WithValue(ctx, transactionKey, fdb.Transaction(nil))
for { for {
// Collect one batch of entries // Collect one batch of entries
var entriesToDelete []util.FullPath var entriesToDelete []util.FullPath
var subDirectories []util.FullPath var subDirectories []util.FullPath
// List entries - we'll process BATCH_SIZE at a time // List entries - we'll process BATCH_SIZE at a time
_, err := store.ListDirectoryEntries(ctx, fullpath, "", true, int64(BATCH_SIZE), func(entry *filer.Entry) bool {
_, err := store.ListDirectoryEntries(ctxNoTxn, fullpath, "", true, int64(BATCH_SIZE), func(entry *filer.Entry) bool {
entriesToDelete = append(entriesToDelete, entry.FullPath) entriesToDelete = append(entriesToDelete, entry.FullPath)
if entry.IsDirectory() { if entry.IsDirectory() {
subDirectories = append(subDirectories, entry.FullPath) subDirectories = append(subDirectories, entry.FullPath)
@ -328,7 +331,7 @@ func (store *FoundationDBStore) deleteFolderChildrenInBatches(ctx context.Contex
// Recursively delete subdirectories first (also in batches) // Recursively delete subdirectories first (also in batches)
for _, subDir := range subDirectories { for _, subDir := range subDirectories {
if err := store.deleteFolderChildrenInBatches(ctx, subDir); err != nil {
if err := store.deleteFolderChildrenInBatches(ctxNoTxn, subDir); err != nil {
return err return err
} }
} }

Loading…
Cancel
Save