Comments (9)
Thanks for spotting this. Your workaround is smart but what about fixing it by a compressor reset() performed in that specific case when block is better uncompressed?
if (compressor.getBytesRead() <= compressor.getBytesWritten()) {
// write uncompressed data block
byte[] uncompressed = ((Lz4Compressor) compressor).uncompressedBytes();
rawWriteInt(uncompressed.length);
int checksum = Lz4Compressor.xxhash32(uncompressed, 0, uncompressed.length, 0);
rawWriteInt(checksum);
out.write(uncompressed, 0, uncompressed.length);
compressor.reset(); // reset compressor buffers
}
Last line should work just fine. If you have such corner case reproducible, would you mind trying that?
from 4mc.
Hi, when calling compressor.reset(), you also reset finish to false, which will also lead compressor.finished() to false. A call to compressor.finish() should also be made after compressor.reset();
My current fix: use maxInputSize instead of FOURMC_BLOCK_SIZE
// maxInputSize for feeding to compressor.
// Called MAX_INPUT_SIZE in other CompressorStream, change to maxInputSize for style check pass.
final int maxInputSize;
// Use max input size instead of FourMcCodec.FOURMC_BLOCK_SIZE.
int overhead = Lz4Compressor.compressBound(bufferSize) - bufferSize;
maxInputSize = bufferSize - overhead;
if (len + limlen > maxInputSize && limlen > 0) {
finish();
compressor.reset();
}
if (len > maxInputSize) {
do {
int bufLen = Math.min(len, maxInputSize);
// It's essential that we make sure input length(bufLen) <= FOUR_BLOCK_SIZE. Otherwise, we will got
// a wrong decision whether we use uncompressed data directly or not, which will also trigger a
// BufferOverflow exception if we read too much uncompressed data.
compressor.setInput(b, off, bufLen);
finish();
compressor.reset();
off += bufLen;
len -= bufLen;
} while (len > 0);
return;
}
I will try your fix and report back.
from 4mc.
And yes, this fixes the problem. You can use testCodec to reproduce this case
if (compressor.getBytesRead() <= compressor.getBytesWritten()) {
// write uncompressed data block
byte[] uncompressed = ((Lz4Compressor) compressor).uncompressedBytes();
rawWriteInt(uncompressed.length);
int checksum = Lz4Compressor.xxhash32(uncompressed, 0, uncompressed.length, 0);
rawWriteInt(checksum);
out.write(uncompressed, 0, uncompressed.length);
compressor.reset(); // reset compressor buffers
compressor.finish(); // set compressor to be finished.
}
from 4mc.
Perfect, I'll commit our fix as well for upcoming release. Thanks again.
from 4mc.
Ah, I forgot to mention there is another case in the code.
createCompressor in FourMcCodec.java should use a fixed directBufferSize(4MB) rather than a user configurable size. (I already used a fixed size when testing)
If the configured block size is 1MB, there will be 4 calls of FourMcOutputStream.compress() for 4MB input.
For incompressible data, the (compressor.getBytesRead() <= compressor.getBytesWritten) will always be false in the first 3 calls, writes compressed data larger than original data(unexpected). The last call will try to read all the input(4MB), which also raises a BufferUnderFlowException (The uncompressedBuf has only 1MB capacity, and bytesRead is 4MB).
And if the configured block size is near 4MB and incompressible and lz4_compressBound(configured_block_size) >= 4MB, then the fix we proposed above will lose (4MB-configured_block_size) incompressible data.
from 4mc.
@carlomedas ping
from 4mc.
OK so the fix to this would just be to remove the read from configuration and hardcode it to the max size of 4MB?
Sounds reasonable because anyways that size is best for big-data.
TBH I'm not able to understand 100% the issue you reported because it's long time I didn't look at that code, so doing a proper fix for this use case would require much longer time and introduce non trivial risk...
That's why your idea of fix sounds very good. Let me know and I'll commit that as well for upcoming release of 4mc with embedded libraries).
TIA.
from 4mc.
OK so the fix to this would just be to remove the read from configuration and hardcode it to the max size of 4MB?
Yes, that's the fix, createCompressor in FourMcCodec uses a hardcoded maximum 4MB size.
It's indeed a corner case.
from 4mc.
Done in 4mc 1.4.0
from 4mc.
Related Issues (20)
- Create DataSet using SparkSession HOT 1
- Commit 17c36e08653162f6956ef27f55c96c20425df4b8 breaks test units HOT 1
- Fix Typo in FourMzTextInputFormat
- Request: upload maven artifact for java library HOT 3
- Consider changing license to Apache?
- PySpark Example doesn't work HOT 3
- could you provide a 4mc example for flink HOT 1
- The Travis link is broken
- 4mz - Zstd - cannot load csv.4mz into Spark (4mc works correctly) HOT 2
- how to use 4mc/4mz when write to json or parquet HOT 1
- how to use 4mc tool for linux fs batch processing and logging HOT 2
- null pointer exception HOT 2
- Issue creating output stream
- Update lz4 and zstd version? HOT 7
- Decompressing from stdin HOT 2
- why is FourMcTextInputFormat not an InputFormat? HOT 1
- How to use 4mc in Hive? HOT 1
- Requesting to Publish FourMC Project to maven Central Repository HOT 6
- Can't load AMD 64-bit .so on a AARCH64-bit platform HOT 1
- release-3.0.0 make error on centos7.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 4mc.