-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ByteBufBsonDocument & ByteBufBsonArray refactorings #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ByteBuf
Are you sure you want to change the base?
Conversation
* Now implement `Closeable` to track and manage lifecycle with try-with-resources * `ByteBufBsonDocument`: Added resource tracking, OP_MSG parsing, caching strategy * `ByteBufBsonArray`: Added resource tracking and cleanup CommandMessage Changes: * `getCommandDocument()` returns `ByteBufBsonDocument` (was `BsonDocument`) * Delegates document composition to `ByteBufBsonDocument` * Simplified `OP_MSG` document sequence parsing JAVA-6010
ByteBufBsonDocument & ByteBufBsonArray Refactoring SummarySummary of ChangesWhat Changed
Performance Characteristics
Backward Compatibility
Recommendations for Usage
OverviewThis refactoring introduces comprehensive resource lifecycle management to Key Files Modified:
Resource Tracking ArchitectureByteBufBsonDocument Tracking StrategyThe private final transient List<Closeable> trackedResources;Three-Tier Tracking Pattern:
ByteBufBsonArray Tracking Strategyprivate final List<Closeable> trackedResources = new ArrayList<>();Similar to
Resource Release PatternBoth classes implement identical cleanup logic: for (Closeable resource : trackedResources) {
try {
resource.close();
} catch (Exception e) {
// Log and continue closing other resources
}
}This ensures:
OP_MSG Command Message SupportMongoDB OP_MSG Protocol ParsingThe refactoring adds native support for MongoDB's OP_MSG (OpCode 2013) wire protocol format: public static ByteBufBsonDocument createCommandMessage(final CompositeByteBuf commandMessageByteBuf)Wire Format Handled: Components:
Example Use Case: Insert Command When accessed via SequenceField Inner ClassThe private static final class SequenceField {
private final ByteBuf sequenceByteBuf;
private final List<Closeable> trackedResources;
private List<BsonDocument> documents; // Lazy-loaded cache
}Key Operations:
Caching StrategyThe Cached Fields
Caching Benefits
Computational Complexity Analysis
Legend:
Complexity Patterns
Performance ImplicationsMemory PerformancePositive:
Trade-offs:
CPU PerformancePositive:
Potential Concerns:
Latency Characteristics
CommandMessage IntegrationThe refactoring changes Before: BsonDocument getCommandDocument() // Returned regular BsonDocumentAfter: ByteBufBsonDocument getCommandDocument() // Returns ByteBufBsonDocumentKey Changes:
Improved TestingTest Migration: Groovy Specifications → Java TestsRemoved:
Added:
Test Coverage ImprovementsByteBufBsonDocumentTest.java:
CommandMessageTest.java:
Testing Improvements Summary
|
Closeableto track and manage lifecycle with try-with-resourcesByteBufBsonDocument: Added resource tracking, OP_MSG parsing, caching strategyByteBufBsonArray: Added resource tracking and cleanupCommandMessage Changes:
getCommandDocument()returnsByteBufBsonDocument(wasBsonDocument)ByteBufBsonDocumentOP_MSGdocument sequence parsingInternalStreamConnection Changes:
CommandDocument.Test Changes:
JAVA-6010