Skip to content
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

[Enhancement] Support large json in image #48569

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

gengjun-git
Copy link
Contributor

@gengjun-git gengjun-git commented Jul 18, 2024

Why I'm doing:

Currently, JSON serialization supports a maximum of 2G, because serialization converts the object into a JSON string first, and then writes the string into the image file, and the maximum size of a string in Java is only 2G.

What I'm doing:

To support large json string, we can use the stream api of GSON: JsonWriter and JsonReader.
Since we cannot know the length of the string in advance, so a new image file format is introduced: a json string must begin with "{" or "[", so primitive type is not supported, and there is nothing between the json string. To support rollback, we use a double write solution. The dir format is as follows

meta/image
         image.111
         /v2
              image.111
              checksum.111

meta/image/image.111 is the old format image file, and meta/image/v2/image.111 is the new format image file. Since the JsonReader will cache some chars in advance, so we cannot calculate the checksum of the specific meta-block, and the checksum is put into another file checksum.111;

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

Path checksumPath = Path.of(imageDir, "v2", Storage.CHECKSUM + "." + imageJournalId);
File checksumFile = new File(checksumPath.toUri());
if (!checksumFile.exists()) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should treat checksum seriously, this shouldn't happend, we should throw an exception explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

long expectedCheckSum = Long.parseLong(Files.readString(checksumPath));
try (CheckedInputStream in = new CheckedInputStream(new FileInputStream(imageFile), new CRC32())) {
byte[] bytes = new byte[8192];
while (in.read(bytes) != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add log to check how long does this take

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use the checkedInputStream to judge the checksum at the end. So no pre-check required.

while (in.read(bytes) != -1) {
}

long realCheckSum = in.getChecksum().getValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Besides, if we use checkedInputStream to read data from v2 image file at the beginning, we don't need to checksum again? just like SRMetaBlockReader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I use the checkedInputStream to judge the checksum at the end.

@Override
public void writeJson(Object object) throws IOException, SRMetaBlockException {
if (isBasicType(object)) {
throw new SRMetaBlockException("can not write primitive type");
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

@gengjun-git gengjun-git Aug 13, 2024

Choose a reason for hiding this comment

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

Two adjacent primitive types will be considered as one when reading.

Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Copy link

sonarcloud bot commented Aug 14, 2024

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 309 / 484 (63.84%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/persist/Storage.java 0 1 00.00% [262]
🔵 com/starrocks/http/meta/MetaBaseAction.java 0 2 00.00% [102, 103]
🔵 com/starrocks/leader/MetaHelper.java 0 26 00.00% [93, 94, 95, 96, 98, 99, 100, 101, 102, 105, 106, 107, 108, 111, 114, 116, 117, 119, 121, 122, 127, 128, 132, 133, 134, 136]
🔵 com/starrocks/http/meta/MetaService.java 0 32 00.00% [70, 99, 102, 103, 104, 105, 108, 122, 123, 124, 125, 127, 128, 129, 130, 133, 161, 162, 163, 192, 267, 268, 269, 270, 273, 279, 283, 284, 286, 315, 316, 318]
🔵 com/starrocks/server/NodeMgr.java 1 15 06.67% [705, 706, 710, 711, 712, 713, 716, 717, 718, 720, 721, 723, 725, 728]
🔵 com/starrocks/leader/Checkpoint.java 7 31 22.58% [153, 154, 184, 185, 186, 191, 193, 194, 195, 196, 198, 199, 200, 202, 203, 204, 205, 214, 215, 217, 218, 220, 223, 225]
🔵 com/starrocks/persist/ImageLoader.java 15 40 37.50% [65, 73, 74, 75, 76, 78, 81, 85, 86, 88, 93, 94, 96, 98, 99, 100, 102, 105, 106, 107, 108, 109, 110, 111, 114]
🔵 com/starrocks/persist/StorageInfo.java 2 4 50.00% [51, 64]
🔵 com/starrocks/persist/metablock/IntObject.java 4 6 66.67% [33, 34]
🔵 com/starrocks/persist/metablock/LongObject.java 4 6 66.67% [32, 33]
🔵 com/starrocks/persist/MetaCleaner.java 5 7 71.43% [73, 97]
🔵 com/starrocks/persist/metablock/SRMetaBlockReaderV2.java 30 42 71.43% [59, 75, 76, 78, 93, 95, 96, 97, 98, 99, 101, 132]
🔵 com/starrocks/load/DeleteMgr.java 3 4 75.00% [921]
🔵 com/starrocks/server/GlobalStateMgr.java 50 65 76.92% [1462, 1502, 1504, 1505, 1507, 1511, 1512, 1525, 1554, 1555, 1558, 1567, 1620, 1622, 2468]
🔵 com/starrocks/persist/metablock/SRMetaBlockWriterV1.java 25 32 78.12% [53, 54, 55, 57, 58, 59, 60]
🔵 com/starrocks/persist/metablock/SRMetaBlockReaderV1.java 42 49 85.71% [96, 111, 116, 131, 132, 155, 156]
🔵 com/starrocks/persist/metablock/SRMetaBlockWriterV2.java 26 27 96.30% [39]
🔵 com/starrocks/load/pipe/PipeManager.java 2 2 100.00% []
🔵 com/starrocks/load/pipe/PipeRepo.java 1 1 100.00% []
🔵 com/starrocks/load/streamload/StreamLoadMgr.java 2 2 100.00% []
🔵 com/starrocks/load/ExportMgr.java 2 2 100.00% []
🔵 com/starrocks/catalog/CatalogRecycleBin.java 4 4 100.00% []
🔵 com/starrocks/authentication/AuthenticationMgr.java 3 3 100.00% []
🔵 com/starrocks/persist/ImageWriter.java 19 19 100.00% []
🔵 com/starrocks/statistic/AnalyzeMgr.java 7 7 100.00% []
🔵 com/starrocks/scheduler/TaskManager.java 3 3 100.00% []
🔵 com/starrocks/server/CatalogMgr.java 2 2 100.00% []
🔵 com/starrocks/load/loadv2/LoadMgr.java 2 2 100.00% []
🔵 com/starrocks/transaction/GlobalTransactionMgr.java 2 2 100.00% []
🔵 com/starrocks/backup/BackupHandler.java 2 2 100.00% []
🔵 com/starrocks/server/LocalMetastore.java 4 4 100.00% []
🔵 com/starrocks/encryption/KeyMgr.java 2 2 100.00% []
🔵 com/starrocks/catalog/ColocateTableIndex.java 1 1 100.00% []
🔵 com/starrocks/common/util/SmallFileMgr.java 2 2 100.00% []
🔵 com/starrocks/persist/ImageFormatVersion.java 3 3 100.00% []
🔵 com/starrocks/alter/AlterJobMgr.java 5 5 100.00% []
🔵 com/starrocks/catalog/ResourceGroupMgr.java 2 2 100.00% []
🔵 com/starrocks/lake/compaction/CompactionMgr.java 2 2 100.00% []
🔵 com/starrocks/catalog/GlobalFunctionMgr.java 2 2 100.00% []
🔵 com/starrocks/server/StorageVolumeMgr.java 1 1 100.00% []
🔵 com/starrocks/privilege/AuthorizationMgr.java 7 7 100.00% []
🔵 com/starrocks/replication/ReplicationMgr.java 1 1 100.00% []
🔵 com/starrocks/catalog/ResourceMgr.java 1 1 100.00% []
🔵 com/starrocks/qe/VariableMgr.java 3 3 100.00% []
🔵 com/starrocks/scheduler/mv/MaterializedViewMgr.java 2 2 100.00% []
🔵 com/starrocks/load/routineload/RoutineLoadMgr.java 2 2 100.00% []
🔵 com/starrocks/catalog/DictionaryMgr.java 1 1 100.00% []
🔵 com/starrocks/plugin/PluginMgr.java 2 2 100.00% []
🔵 com/starrocks/load/InsertOverwriteJobMgr.java 1 1 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@wyb wyb enabled auto-merge (squash) August 16, 2024 05:08
@andyziye andyziye disabled auto-merge August 16, 2024 06:06
@andyziye andyziye merged commit 78715a7 into StarRocks:main Aug 16, 2024
55 of 56 checks passed
Copy link

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label Aug 16, 2024
Copy link
Contributor

mergify bot commented Aug 16, 2024

backport branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 16, 2024
Signed-off-by: gengjun-git <[email protected]>
(cherry picked from commit 78715a7)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/authentication/AuthenticationMgr.java
#	fe/fe-core/src/main/java/com/starrocks/http/meta/MetaService.java
#	fe/fe-core/src/main/java/com/starrocks/leader/Checkpoint.java
#	fe/fe-core/src/main/java/com/starrocks/server/LocalMetastore.java
wanpengfei-git pushed a commit that referenced this pull request Aug 19, 2024
gengjun-git added a commit that referenced this pull request Oct 9, 2024
## Why I'm doing:
Backport the stream reading of #48569

Signed-off-by: gengjun-git <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants