Skip to content

KAFKA-20492: Prepare DBAccessor for txn support#22142

Open
nicktelford wants to merge 1 commit intoapache:trunkfrom
nicktelford:KIP-892/txn-rocksdb-accessor
Open

KAFKA-20492: Prepare DBAccessor for txn support#22142
nicktelford wants to merge 1 commit intoapache:trunkfrom
nicktelford:KIP-892/txn-rocksdb-accessor

Conversation

@nicktelford
Copy link
Copy Markdown
Contributor

@nicktelford nicktelford commented Apr 24, 2026

Moves iterator construction (all, range, prefixScan) from
SingleColumnFamilyAccessor into default methods on DBAccessor.
SingleColumnFamilyAccessor now delegates to the accessor, allowing
future DBAccessor implementations (e.g. a transactional wrapper) to
override iteration behaviour.

Adds no-op commitStagedWrites() and rollbackStagedWrites() defaults to
DBAccessor, and calls commitStagedWrites() from
AbstractColumnFamilyAccessor.commit(). These are no-ops for the existing
DirectDBAccessor but provide the hook for a transactional accessor to
flush buffered writes atomically with offset commits.

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Reviewers: Bill Bejeck bbejeck@apache.org

Moves iterator construction (all, range, prefixScan) from
SingleColumnFamilyAccessor into default methods on DBAccessor.
SingleColumnFamilyAccessor now delegates to the accessor, allowing
future DBAccessor implementations (e.g. a transactional wrapper) to
override iteration behaviour.

Adds no-op commitStagedWrites() and rollbackStagedWrites() defaults
to DBAccessor, and calls commitStagedWrites() from
AbstractColumnFamilyAccessor.commit(). These are no-ops for the
existing DirectDBAccessor but provide the hook for a transactional
accessor to flush buffered writes atomically with offset commits.
@github-actions github-actions Bot added triage PRs from the community streams small Small PRs labels Apr 24, 2026
Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nicktelford for the PR, I've made a pass

}

default void commitStagedWrites() throws RocksDBException {
// no-op for non-transactional accessors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this throw an UnsupportedOperationException by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is a no-op is for the existing DirectDBAccessor. I could make these not have a default implementation and move the no-op to an @Override on DirectDBAccessor if you'd prefer?

}

default void rollbackStagedWrites() {
// no-op for non-transactional accessors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

void reset();
void close();

default ManagedKeyValueIterator<Bytes, byte[]> all(final ColumnFamilyHandle cf, final String storeName, final boolean forward) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we could use some tests for this addition or are the existing ones enough coverage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking on this surfaced a subtle bug: the DualColumnFamilyAccessor hasn't been updated to use DBAccessor to construct its iterators. This means that when the TransactionalDBAccessor is later introduced, stores that use dual column families (e.g. RocksDBTimestampedStore) would fail to read-your-own-writes on calls to all, prefixScan and range.

I'm working on a fix for this and will include unit tests that verify DBAccessor#{all,range,prefixScan} are being called as expected.

}
}
}
accessor.commitStagedWrites();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the AbstractColumnFamilyAccessorTest to validate this call is made

}

default ManagedKeyValueIterator<Bytes, byte[]> range(final ColumnFamilyHandle cf, final String storeName,
final Bytes from, final Bytes to,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: align the parameters

}

default ManagedKeyValueIterator<Bytes, byte[]> prefixScan(final ColumnFamilyHandle cf, final String storeName,
final Bytes prefix, final Bytes to) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}
}
accessor.commitStagedWrites();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AbstractColumnFamilyAccessor.commit(accessor, Position storePosition) doesn't call commit - I'm assumign this is intential, but I wanted to confirm maybe add a comment on the method why it doesn't?

@github-actions github-actions Bot removed the triage PRs from the community label May 1, 2026
@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented May 1, 2026

Kicked off a system test will post results later

@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented May 1, 2026

System tests passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants