Skip to content

Commit e18301c

Browse files
fix: NPE when compression algorithm is not set
- improve KANZI compression settings - update documentation
1 parent 5c39d32 commit e18301c

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

h2/src/docsrc/html/advanced.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ <h3 id="direct_one_phase_recover_tool">Direct Recover</h3>
10731073
java -Xmx8g -cp "h2-2.3.239-SNAPSHOT.jar" org.h2.tools.DirectRecover -dir ~/ -db testdb -compress gzip
10741074

10751075
# resulting SQL script files on a AMD Zen3 Ryzen5:
1076-
# KANZI: testdb.h2.sql.knz (114.1 MB in 128 secs)
1076+
# KANZI: testdb.h2.sql.knz ( 99.7 MB in 106 secs)
10771077
# BZip2: testdb.h2.sql.bz2 (153.7 MB in 18 mins)
10781078
# GZip: testdb.h2.sql.gz (207.4 MB in 74 secs)
10791079
</pre>

h2/src/main/org/h2/tools/CompressTool.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,15 @@ public static OutputStream createKanziOutputStream(OutputStream baseOutputStream
110110
// Create configuration map with proper Kanzi parameters
111111
java.util.Map<String, Object> configMap = new java.util.HashMap<>();
112112

113-
// Basic compression settings
114-
configMap.put("transform", "LZP+BWT"); // Good for text
115-
configMap.put("entropy", "CM"); // Text and structured data
116-
configMap.put("blockSize", 128 * 1024 * 1024); // 128MB blocks
113+
// Best compression settings (brute tested on a 1.7 GB database)
114+
// 88658331 kanzi -x64 -b 256m -t RLT+PACK+LZP -e TPAQX
115+
// 88654035 kanzi -x64 -b 256m -t RLT+PACK+LZP+RLT -e TPAQX
116+
// 85411430 kanzi -x64 -b 256m -t TEXT+RLT+LZP+PACK -e TPAQX
117+
// 85397152 kanzi -x64 -b 256m -t TEXT+RLT+LZP+PACK+RLT -e TPAQX
118+
119+
configMap.put("transform", "TEXT+RLT+LZP+PACK+RLT");// Good for text
120+
configMap.put("entropy", "TPAQ"); // Text and structured data
121+
configMap.put("blockSize", 64 * 1024 * 1024); // 128MB blocks
117122
configMap.put("level", 9); // Max. compression level
118123
configMap.put("checksum", 64); // Enable checksums
119124

@@ -153,6 +158,8 @@ public static InputStream createKanziInputStream(InputStream inputStream, Execut
153158
InputStream.class,
154159
java.util.Map.class
155160
);
161+
// workaround Zero byte EOF issue
162+
// it has been fixed only recently so we should still guard for a while
156163
return new ZeroBytesEOFInputStream( (InputStream) constructor.newInstance(inputStream, configMap));
157164

158165
} catch (ClassNotFoundException e) {

h2/src/main/org/h2/tools/CompressionType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public enum CompressionType {
1515
LZF;
1616

1717
public static CompressionType from(String type) {
18-
return Enum.valueOf(CompressionType.class, type.toUpperCase(Locale.ENGLISH));
18+
return type==null || type.isEmpty()
19+
? NONE
20+
: Enum.valueOf(CompressionType.class, type.toUpperCase(Locale.ENGLISH));
1921
}
2022
}

0 commit comments

Comments
 (0)