fix(filer): remove cancellation guard from RollbackTransaction and clean up #8909 (#8916)

* fix(filer): remove cancellation guard from RollbackTransaction and clean up #8909

RollbackTransaction is a cleanup operation that must succeed even when
the context is cancelled — guarding it causes the exact orphaned state
that #8909 was trying to prevent.

Also:
- Use single-evaluation `if err := ctx.Err(); err != nil` pattern
  instead of double-calling ctx.Err()
- Remove spurious blank lines before guards
- Add context.DeadlineExceeded test coverage
- Simplify tests from ~230 lines to ~130 lines

* fix(filer): call cancel() in expiredCtx and test rollback with expired context

- Call cancel() instead of suppressing it to avoid leaking timer resources
- Test RollbackTransaction with both cancelled and expired contexts
This commit is contained in:
Chris Lu
2026-04-03 17:55:27 -07:00
committed by GitHub
parent d5128f00f1
commit 36f37b9b6a
2 changed files with 142 additions and 258 deletions

View File

@@ -128,10 +128,8 @@ func (fsw *FilerStoreWrapper) Initialize(configuration util.Configuration, prefi
}
func (fsw *FilerStoreWrapper) InsertEntry(ctx context.Context, entry *Entry) error {
// Check if context was already cancelled before ignoring cancellation
// This prevents writing metadata for operations that have already failed
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(entry.FullPath)
@@ -160,9 +158,8 @@ func (fsw *FilerStoreWrapper) InsertEntry(ctx context.Context, entry *Entry) err
// InsertEntryKnownAbsent skips the pre-insert FindEntry path when the caller has
// already established that the target path does not exist.
func (fsw *FilerStoreWrapper) InsertEntryKnownAbsent(ctx context.Context, entry *Entry) error {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(entry.FullPath)
@@ -187,9 +184,8 @@ func (fsw *FilerStoreWrapper) InsertEntryKnownAbsent(ctx context.Context, entry
}
func (fsw *FilerStoreWrapper) UpdateEntry(ctx context.Context, entry *Entry) error {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(entry.FullPath)
@@ -249,9 +245,8 @@ func (fsw *FilerStoreWrapper) FindEntry(ctx context.Context, fp util.FullPath) (
}
func (fsw *FilerStoreWrapper) DeleteEntry(ctx context.Context, fp util.FullPath) (err error) {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(fp)
@@ -281,9 +276,8 @@ func (fsw *FilerStoreWrapper) DeleteEntry(ctx context.Context, fp util.FullPath)
}
func (fsw *FilerStoreWrapper) DeleteOneEntry(ctx context.Context, existingEntry *Entry) (err error) {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(existingEntry.FullPath)
@@ -309,9 +303,8 @@ func (fsw *FilerStoreWrapper) DeleteOneEntry(ctx context.Context, existingEntry
}
func (fsw *FilerStoreWrapper) DeleteFolderChildren(ctx context.Context, fp util.FullPath) (err error) {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(fp + "/")
@@ -419,28 +412,22 @@ func (fsw *FilerStoreWrapper) prefixFilterEntries(ctx context.Context, dirPath u
}
func (fsw *FilerStoreWrapper) BeginTransaction(ctx context.Context) (context.Context, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
if err := ctx.Err(); err != nil {
return nil, err
}
ctx = context.WithoutCancel(ctx)
return fsw.getDefaultStore().BeginTransaction(ctx)
}
func (fsw *FilerStoreWrapper) CommitTransaction(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
return fsw.getDefaultStore().CommitTransaction(ctx)
}
func (fsw *FilerStoreWrapper) RollbackTransaction(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
}
ctx = context.WithoutCancel(ctx)
return fsw.getDefaultStore().RollbackTransaction(ctx)
}
@@ -450,9 +437,8 @@ func (fsw *FilerStoreWrapper) Shutdown() {
}
func (fsw *FilerStoreWrapper) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
return fsw.getDefaultStore().KvPut(ctx, key, value)
@@ -462,9 +448,8 @@ func (fsw *FilerStoreWrapper) KvGet(ctx context.Context, key []byte) (value []by
return fsw.getDefaultStore().KvGet(ctx, key)
}
func (fsw *FilerStoreWrapper) KvDelete(ctx context.Context, key []byte) (err error) {
if ctx.Err() != nil {
return ctx.Err()
if err := ctx.Err(); err != nil {
return err
}
ctx = context.WithoutCancel(ctx)
return fsw.getDefaultStore().KvDelete(ctx, key)