From f9a671ac37174365609c42635c801aeae565e1d2 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 12 Nov 2018 19:59:42 -0800 Subject: [PATCH] [cli] Add rsyncable --- programs/fileio.c | 7 +++++++ programs/fileio.h | 1 + programs/zstd.1.md | 8 ++++++++ programs/zstdcli.c | 6 +++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/programs/fileio.c b/programs/fileio.c index c24f4def..705a5660 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -307,6 +307,12 @@ void FIO_setAdaptiveMode(unsigned adapt) { EXM_THROW(1, "Adaptive mode is not compatible with single thread mode \n"); g_adaptiveMode = adapt; } +static U32 g_rsyncable = 0; +void FIO_setRsyncable(unsigned rsyncable) { + if ((rsyncable>0) && (g_nbWorkers==0)) + EXM_THROW(1, "Rsyncable mode is not compatible with single thread mode \n"); + g_rsyncable = rsyncable; +} static int g_minAdaptLevel = -50; /* initializing this value requires a constant, so ZSTD_minCLevel() doesn't work */ void FIO_setAdaptMin(int minCLevel) { @@ -557,6 +563,7 @@ static cRess_t FIO_createCResources(const char* dictFileName, int cLevel, DISPLAYLEVEL(3,"set overlapLog = %u \n", g_overlapLog); CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_p_overlapSizeLog, g_overlapLog) ); } + CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_p_rsyncable, g_rsyncable) ); #endif /* dictionary */ CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, srcSize) ); /* set the value temporarily for dictionary loading, to adapt compression parameters */ diff --git a/programs/fileio.h b/programs/fileio.h index 4c7049cb..8edb7dfe 100644 --- a/programs/fileio.h +++ b/programs/fileio.h @@ -65,6 +65,7 @@ void FIO_setNotificationLevel(unsigned level); void FIO_setOverlapLog(unsigned overlapLog); void FIO_setRemoveSrcFile(unsigned flag); void FIO_setSparseWrite(unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */ +void FIO_setRsyncable(unsigned rsyncable); /*-************************************* diff --git a/programs/zstd.1.md b/programs/zstd.1.md index c0c04698..4920ac01 100644 --- a/programs/zstd.1.md +++ b/programs/zstd.1.md @@ -144,6 +144,14 @@ the last one takes effect. Due to the chaotic nature of dynamic adaptation, compressed result is not reproducible. _note_ : at the time of this writing, `--adapt` can remain stuck at low speed when combined with multiple worker threads (>=2). +* `--rsyncable` : + `zstd` will periodically synchronize the compression state to make the + compressed file more rsync-friendly. There is a negligible impact to + compression ratio, and the faster compression levels will see a small + compression speed hit. + This feature does not work with `--single-thread`. You probably don't want + to use it with long range mode, since it will decrease the effectiveness of + the synchronization points, but your milage may vary. * `-D file`: use `file` as Dictionary to compress or decompress FILE(s) * `--no-dictID`: diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 153de961..9f908355 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -143,6 +143,7 @@ static int usage_advanced(const char* programName) #ifdef ZSTD_MULTITHREAD DISPLAY( " -T# : spawns # compression threads (default: 1, 0==# cores) \n"); DISPLAY( " -B# : select size of each job (default: 0==automatic) \n"); + DISPLAY( " --rsyncable : compress using a rsync-friendly method (-B sets block size) \n"); #endif DISPLAY( "--no-dictID : don't write dictID into header (dictionary compression)\n"); DISPLAY( "--[no-]check : integrity check (default: enabled) \n"); @@ -475,6 +476,7 @@ int main(int argCount, const char* argv[]) adapt = 0, adaptMin = MINCLEVEL, adaptMax = MAXCLEVEL, + rsyncable = 0, nextArgumentIsOutFileName = 0, nextArgumentIsMaxDict = 0, nextArgumentIsDictID = 0, @@ -607,6 +609,7 @@ int main(int argCount, const char* argv[]) #ifdef ZSTD_LZ4COMPRESS if (!strcmp(argument, "--format=lz4")) { suffix = LZ4_EXTENSION; FIO_setCompressionType(FIO_lz4Compression); continue; } #endif + if (!strcmp(argument, "--rsyncable")) { rsyncable = 1; continue; } /* long commands with arguments */ #ifndef ZSTD_NODICT @@ -1052,6 +1055,7 @@ int main(int argCount, const char* argv[]) FIO_setAdaptiveMode(adapt); FIO_setAdaptMin(adaptMin); FIO_setAdaptMax(adaptMax); + FIO_setRsyncable(rsyncable); if (adaptMin > cLevel) cLevel = adaptMin; if (adaptMax < cLevel) cLevel = adaptMax; @@ -1060,7 +1064,7 @@ int main(int argCount, const char* argv[]) else operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName, suffix, dictFileName, cLevel, compressionParams); #else - (void)suffix; (void)adapt; (void)ultra; (void)cLevel; (void)ldmFlag; /* not used when ZSTD_NOCOMPRESS set */ + (void)suffix; (void)adapt; (void)rsyncable; (void)ultra; (void)cLevel; (void)ldmFlag; /* not used when ZSTD_NOCOMPRESS set */ DISPLAY("Compression not supported \n"); #endif } else { /* decompression or test */