Skip to content

Commit 07caa8a

Browse files
Fix for Block Size
In some cases, the given block size could be wrong on receiver side, in particular when it receives from its own initiative (Pull) a file and when one of the server has an upper limit below this requested size. This fix this issue.
1 parent 4d2d9e4 commit 07caa8a

File tree

10 files changed

+133
-9
lines changed

10 files changed

+133
-9
lines changed

WaarpCommon/src/main/java/org/waarp/common/utility/WaarpNettyUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.netty.buffer.PooledByteBufAllocator;
2525
import io.netty.channel.ChannelOption;
2626
import io.netty.channel.EventLoopGroup;
27+
import io.netty.channel.WriteBufferWaterMark;
2728
import io.netty.channel.socket.nio.NioServerSocketChannel;
2829
import io.netty.channel.socket.nio.NioSocketChannel;
2930
import io.netty.util.concurrent.Future;
@@ -35,7 +36,11 @@
3536
public final class WaarpNettyUtil {
3637

3738
private static final int TIMEOUT_MILLIS = 1000;
39+
// Default optimal value for Waarp
3840
private static final int BUFFER_SIZE_1MB = 1048576;
41+
// Default optimal value from Netty (tested as correct for Waarp)
42+
private static final int DEFAULT_LOW_WATER_MARK = 32 * 1024;
43+
private static final int DEFAULT_HIGH_WATER_MARK = 64 * 1024;
3944

4045
private WaarpNettyUtil() {
4146
}
@@ -57,6 +62,9 @@ public static void setBootstrap(Bootstrap bootstrap, EventLoopGroup group,
5762
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
5863
bootstrap.option(ChannelOption.SO_RCVBUF, BUFFER_SIZE_1MB);
5964
bootstrap.option(ChannelOption.SO_SNDBUF, BUFFER_SIZE_1MB);
65+
bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK,
66+
new WriteBufferWaterMark(DEFAULT_LOW_WATER_MARK,
67+
DEFAULT_HIGH_WATER_MARK));
6068
bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
6169
}
6270

@@ -79,6 +87,9 @@ public static void setServerBootstrap(ServerBootstrap bootstrap,
7987
bootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
8088
bootstrap.childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE_1MB);
8189
bootstrap.childOption(ChannelOption.SO_SNDBUF, BUFFER_SIZE_1MB);
90+
bootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK,
91+
new WriteBufferWaterMark(DEFAULT_LOW_WATER_MARK,
92+
DEFAULT_HIGH_WATER_MARK));
8293
bootstrap
8394
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
8495
}

WaarpR66/src/main/java/org/waarp/openr66/database/data/DbTaskRunner.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,13 @@ public void setRankAtStartup(int rank) {
21502150
}
21512151
}
21522152

2153+
/**
2154+
* @param blocksize the block size to set
2155+
*/
2156+
public void setBlocksize(int blocksize) {
2157+
pojo.setBlockSize(blocksize);
2158+
}
2159+
21532160
/**
21542161
* @param filename the filename to set
21552162
*/

WaarpR66/src/main/java/org/waarp/openr66/protocol/http/restv2/converters/TransferConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static Transfer nodeToNewTransfer(ObjectNode object) {
173173
new Transfer(null, null, -1, false, null, null, 65536);
174174
defaultTransfer.setRequester(serverName());
175175
defaultTransfer.setOwnerRequest(serverName());
176-
defaultTransfer.setBlockSize(65536);
176+
defaultTransfer.setBlockSize(Configuration.configuration.getBlockSize());
177177
defaultTransfer.setTransferInfo("");
178178
defaultTransfer.setStart(new Timestamp(DateTime.now().getMillis()));
179179
final Transfer transfer = parseNode(object, defaultTransfer);

WaarpR66/src/main/java/org/waarp/openr66/protocol/localhandler/TransferActions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ public void request(RequestPacket packet)
212212
}
213213
// Receiver can specify a rank different from database
214214
setRankAtStartupFromRequest(packet, runner);
215+
runner.setBlocksize(packet.getBlocksize());
216+
try {
217+
runner.update();
218+
} catch (WaarpDatabaseException ignored) {
219+
// Ignore
220+
}
215221
logger.debug(
216222
"Filesize: " + packet.getOriginalSize() + ':' + runner.isSender());
217223
boolean shouldInformBack = false;
@@ -287,6 +293,8 @@ private RequestPacket computeBlockSizeFromRequest(RequestPacket packet,
287293
}
288294
// Check if the blocksize is greater than local value
289295
if (Configuration.configuration.getBlockSize() < blocksize) {
296+
logger.warn("Blocksize is greater than allowed {} < {}",
297+
Configuration.configuration.getBlockSize(), blocksize);
290298
blocksize = Configuration.configuration.getBlockSize();
291299
final String sep = localChannelReference.getPartner().getSeperator();
292300
packet = new RequestPacket(packet.getRulename(), packet.getMode(),

WaarpR66/src/test/java/org/waarp/openr66/protocol/it/ScenarioBase.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public abstract class ScenarioBase extends TestAbstract {
8484
private static final String TMP_R66_CONFIG_R1 =
8585
"/tmp/R66/scenario_1_2_3/" + SERVER_1_REWRITTEN_XML;
8686
public static int NUMBER_FILES = 50;
87+
public static int LARGE_SIZE = 2000000;
88+
public static int BLOCK_SIZE = 8192;
89+
8790
private static int r66Pid1 = 999999;
8891
private static int r66Pid2 = 999999;
8992
private static int r66Pid3 = 999999;
@@ -368,7 +371,7 @@ public void test011_SendToItself() throws IOException, InterruptedException {
368371
Assume.assumeNotNull(networkTransaction);
369372
File baseDir = new File("/tmp/R66/scenario_1_2_3/R1/out/");
370373
final File totest =
371-
generateOutFile(baseDir.getAbsolutePath() + "/testTask.txt", 1000);
374+
generateOutFile(baseDir.getAbsolutePath() + "/testTask.txt", 100);
372375
final R66Future future = new R66Future(true);
373376
final SubmitTransfer transaction =
374377
new SubmitTransfer(future, "server1-ssl", "testTask.txt", "rule3",
@@ -394,7 +397,8 @@ public void test012_MultipleSendsSync()
394397
Assume.assumeNotNull(networkTransaction);
395398
File baseDir = new File("/tmp/R66/scenario_1_2_3/R2/out/");
396399
File fileOut = new File(baseDir, "hello");
397-
final File outHello = generateOutFile(fileOut.getAbsolutePath(), 100000);
400+
final File outHello =
401+
generateOutFile(fileOut.getAbsolutePath(), LARGE_SIZE);
398402
ArrayList<R66Future> futures = new ArrayList<R66Future>(NUMBER_FILES);
399403
ExecutorService executorService =
400404
Executors.newFixedThreadPool(NUMBER_FILES);
@@ -406,7 +410,7 @@ public void test012_MultipleSendsSync()
406410
final TestRecvThroughClient transaction =
407411
new TestRecvThroughClient(future, handler, "server2", "hello",
408412
"recvthrough", "Test Multiple RecvThrough",
409-
true, 8192, networkTransaction);
413+
true, BLOCK_SIZE, networkTransaction);
410414
transaction.setNormalInfoAsWarn(false);
411415
executorService.execute(transaction);
412416
}
@@ -418,11 +422,13 @@ public void test012_MultipleSendsSync()
418422
assertTrue(future.isSuccess());
419423
}
420424
long timestop = System.currentTimeMillis();
421-
logger
422-
.warn("RecvThrough {} files from R2" + " ({} seconds, {} per seconds)",
423-
NUMBER_FILES, (timestop - timestart) / 1000,
424-
NUMBER_FILES * 1000 / (timestop - timestart));
425+
logger.warn(
426+
"RecvThrough {} files from R2 ({} seconds, {} per seconds) of " +
427+
"size {} with block size {}", NUMBER_FILES,
428+
(timestop - timestart) / 1000,
429+
NUMBER_FILES * 1000 / (timestop - timestart), LARGE_SIZE, BLOCK_SIZE);
425430
outHello.delete();
431+
FileUtils.forceDeleteRecursiveDir(baseDir);
426432
logger.warn("End {}", Processes.getCurrentMethodName());
427433
}
428434

@@ -511,6 +517,48 @@ public void test04_5000_MultipleSends()
511517
Thread.sleep(5000);
512518
}
513519

520+
@Test
521+
public void test04_5000_MultipleSends_ChangingBlockSize()
522+
throws IOException, InterruptedException {
523+
Assume.assumeTrue("If the Long term tests are allowed",
524+
SystemPropertyUtil.get(IT_LONG_TEST, false));
525+
int lastNumber = NUMBER_FILES;
526+
NUMBER_FILES = 800;
527+
BLOCK_SIZE = 16 * 1024;
528+
test012_MultipleSendsSync();
529+
// Extra sleep to check correctness if necessary on Logs
530+
Thread.sleep(1000);
531+
// Ensure the last send is ok
532+
test011_SendToItself();
533+
// Extra sleep to check correctness if necessary on Logs
534+
Thread.sleep(1000);
535+
BLOCK_SIZE = 64 * 1024;
536+
test012_MultipleSendsSync();
537+
// Extra sleep to check correctness if necessary on Logs
538+
Thread.sleep(1000);
539+
// Ensure the last send is ok
540+
test011_SendToItself();
541+
// Extra sleep to check correctness if necessary on Logs
542+
Thread.sleep(1000);
543+
BLOCK_SIZE = 128 * 1024;
544+
test012_MultipleSendsSync();
545+
// Extra sleep to check correctness if necessary on Logs
546+
Thread.sleep(1000);
547+
// Ensure the last send is ok
548+
test011_SendToItself();
549+
// Extra sleep to check correctness if necessary on Logs
550+
Thread.sleep(1000);
551+
BLOCK_SIZE = 512 * 1024;
552+
test012_MultipleSendsSync();
553+
// Extra sleep to check correctness if necessary on Logs
554+
Thread.sleep(1000);
555+
// Ensure the last send is ok
556+
test011_SendToItself();
557+
// Extra sleep to check correctness if necessary on Logs
558+
Thread.sleep(5000);
559+
NUMBER_FILES = lastNumber;
560+
}
561+
514562
private void waitForAllDone(DbTaskRunner runner) {
515563
while (true) {
516564
try {

WaarpR66/src/test/java/org/waarp/openr66/protocol/junit/NetworkClientTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,51 @@ public void test5_DirectTransfer() throws Exception {
704704
assertEquals("Errors should be 0", 0, error);
705705
}
706706

707+
@Test
708+
public void test5_DirectTransferMultipleBlockSize() throws Exception {
709+
final File totest = generateOutFile("/tmp/R66/out/testTask.txt", 1000000);
710+
final ExecutorService executorService = Executors.newCachedThreadPool();
711+
final int nb = 10;
712+
final R66Future[] arrayFuture = new R66Future[nb];
713+
logger.warn("Start Test of DirectTransfer");
714+
final long time1 = System.currentTimeMillis();
715+
for (int i = 0; i < nb; i++) {
716+
arrayFuture[i] = new R66Future(true);
717+
final TestTransferNoDb transaction =
718+
new TestTransferNoDb(arrayFuture[i], "hostas", "testTask.txt",
719+
"rule3", "Test SendDirect Small", true,
720+
8192 * (i + 1) * 2, DbConstantR66.ILLEGALVALUE,
721+
networkTransaction);
722+
executorService.execute(transaction);
723+
}
724+
int success = 0;
725+
int error = 0;
726+
for (int i = 0; i < nb; i++) {
727+
arrayFuture[i].awaitOrInterruptible();
728+
if (arrayFuture[i].getRunner() != null) {
729+
logger.warn("{} {}", arrayFuture[i].getRunner().getBlocksize(),
730+
8192 * (i + 1) * 2);
731+
assertTrue(
732+
arrayFuture[i].getRunner().getBlocksize() <= 8192 * (i + 1) * 2);
733+
assertTrue(arrayFuture[i].getRunner().getBlocksize() <=
734+
Configuration.configuration.getBlockSize());
735+
dbTaskRunners.add(arrayFuture[i].getRunner());
736+
}
737+
if (arrayFuture[i].isSuccess()) {
738+
success++;
739+
} else {
740+
error++;
741+
}
742+
}
743+
final long time2 = System.currentTimeMillis();
744+
logger.warn("Success: " + success + " Error: " + error + " NB/s: " +
745+
success * 1000 / (time2 - time1));
746+
executorService.shutdown();
747+
totest.delete();
748+
assertEquals("Success should be total", nb, success);
749+
assertEquals("Errors should be 0", 0, error);
750+
}
751+
707752
@Test
708753
public void test5_DirectTransferThroughId() throws Exception {
709754
final File totest = generateOutFile("/tmp/R66/out/testTask.txt", 10);

WaarpR66/src/test/resources/it/scenario_1_2_3/R1/conf/server_1.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<globaldigest>True</globaldigest>
8686
<delaycommand>5000</delaycommand>
8787
<runlimit>600</runlimit>
88+
<blocksize>1048576</blocksize>
8889
</limit>
8990
<db>
9091
<dbdriver>h2</dbdriver>

WaarpR66/src/test/resources/it/scenario_1_2_3/R1/conf/server_1_SQLDB.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
<digest>5</digest>
8585
<globaldigest>True</globaldigest>
8686
<delaycommand>5000</delaycommand>
87-
<runlimit>600</runlimit>
87+
<runlimit>800</runlimit>
88+
<blocksize>1048576</blocksize>
8889
</limit>
8990
<db>
9091
<dbdriver>XXXDRIVERXXX</dbdriver>

WaarpR66/src/test/resources/it/scenario_1_2_3/R2/conf/server_2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<digest>5</digest>
8585
<globaldigest>True</globaldigest>
8686
<runlimit>1000</runlimit>
87+
<blocksize>1048576</blocksize>
8788
</limit>
8889
<db>
8990
<dbdriver>h2</dbdriver>

doc/waarp-r66/source/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Correctifs
3434
request [`#42 <https://github.com/waarp/Waarp-All/pull/42>`__])
3535
- Correction de l'authentification HMAC de l'API REST v2 (pull
3636
request [`#43 <https://github.com/waarp/Waarp-All/pull/43>`__])
37+
- Correction d'un bug sur la taille des paquets (pull
38+
request [`#45 <https://github.com/waarp/Waarp-All/pull/45>`__])
3739

3840
Waarp R66 3.3.3 (2020-05-07)
3941
============================

0 commit comments

Comments
 (0)