-
Notifications
You must be signed in to change notification settings - Fork 115
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
Move file handling logic from RecordItemParser to RecordFileParser #585
Conversation
- Move connection ownership to RecordFileParser - initConnection: earlier RecordItemParser.start() - closeConnection: earlier RecordItemParser.finish() - Move db file handling to RecordFileParser - initFile - closeFileAndCommit: eariler RecordItemParser.completeFile() - Move file testing from RecordItemParserTest to RecordFileParserTest - RecordItemParser is completely agnostic of 'file' concept now. - Remove checks for recordFileRepository from RecordItemParser tests Followup: Remove fileId in t_transactions. Signed-off-by: Apekshit Sharma <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #585 +/- ##
============================================
+ Coverage 64.31% 64.45% +0.14%
Complexity 171 171
============================================
Files 101 101
Lines 3167 3157 -10
Branches 366 363 -3
============================================
- Hits 2037 2035 -2
+ Misses 976 971 -5
+ Partials 154 151 -3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with the direction of this PR. The RecordFileParser
should not have knowledge of database connections, rolling back or postgres specific parsed item handlers.
Recommend moving connection management to PostgresWritingRecordParsedItemHandler
and be opened once per file. It can even be opened once per batch due to the wonders of connection pools. It's fine if RecordFileParser
needs to open a separate connection for updating t_record_files
. Recommend interface segregation principle be used to split file specific logic out from ParsedItemHandler
and into new interface (exact name or parameters can be debated):
public interface StreamFileListener {
void onStart(StreamFileData);
void onEnd(StreamFileData);
}
PostgresWritingRecordParsedItemHandler
should be adapted to implement StreamFileListener
directly (not via ParsedItemHandler) only because he manually manages connections and needs to flush onEnd. Other implementations of ParsedItemHandler like message queues would not need to implement it as they don't batch.
RecordFileParser
should only have knowledge of StreamFileListener
and RecordItemParser
should only have knowledge of ParsedItemHandler
. This would provide a much cleaner separation of layers while still satisfying your concerns.
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Outdated
Show resolved
Hide resolved
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordItemParser.java
Outdated
Show resolved
Hide resolved
hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/domain/Transaction.java
Show resolved
Hide resolved
...in/java/com/hedera/mirror/importer/parser/record/PostgresWritingRecordParsedItemHandler.java
Outdated
Show resolved
Hide resolved
I absolutely agree, don't like the postgres stuff in two places myself. |
…anges for now Signed-off-by: Apekshit Sharma <[email protected]>
last commit was early preview of changes, please take a look. |
Signed-off-by: Apekshit Sharma <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improvement suggestions would be great! There's still so much here (and in general, always), that can be made better.
But if may request, since this PR has grown big and iterations on this will be costly, let's do improvements in followup. There's lot of good stuff here already. :)
...mirror-importer/src/main/java/com/hedera/mirror/importer/parser/record/RecordFileParser.java
Show resolved
Hide resolved
...in/java/com/hedera/mirror/importer/parser/record/PostgresWritingRecordParsedItemHandler.java
Show resolved
Hide resolved
Signed-off-by: Apekshit Sharma <[email protected]>
...or-importer/src/test/java/com/hedera/mirror/importer/parser/record/RecordFileParserTest.java
Outdated
Show resolved
Hide resolved
...or-importer/src/test/java/com/hedera/mirror/importer/parser/record/RecordFileParserTest.java
Outdated
Show resolved
Hide resolved
...in/java/com/hedera/mirror/importer/parser/record/PostgresWritingRecordParsedItemHandler.java
Show resolved
Hide resolved
...irror-importer/src/main/java/com/hedera/mirror/importer/parser/RecordStreamFileListener.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Apekshit Sharma <[email protected]>
Detailed description:
PostgresWritingRecordParsedItemHandler
RecordItemParser
is agnostic of 'file' and database now (except entity repo, to be fixed later)RecordFileParser
is agnostic of database now (except for application state - applicationStatusRepository)RecordFileParserTest
to use mocks rather thantransactionRepository
orrecordFileRepository
.StreamFileListener
andRecordStreamFileListener
RecordFileParser
---depends on -->RecordStreamFileListener
andRecordItemListener
RecordItemParser
--depends on-->RecordParsedItemHandler
t_record_files
. To be removed soon.RecordItemParser
testsSigned-off-by: Apekshit Sharma [email protected]
Which issue(s) this PR fixes:
Partially addresses #566
Special notes for your reviewer:
Checklist