Skip to content

Commit

Permalink
- Correct upper bound of missing messages in Table (https://issues.jb…
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Nov 28, 2017
1 parent d6efbd6 commit 416f3c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/org/jgroups/util/Table.java
Expand Up @@ -677,8 +677,9 @@ public SeqnoList getMissing(int max_msgs) {
int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity; int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity;
if(max_size <= 0) if(max_size <= 0)
return null; return null;
Missing missing=new Missing(start_seqno, capacity, max_size); Missing missing=new Missing(start_seqno, max_size);
forEach(start_seqno, hr-1, missing); long to=max_size > 0? Math.min(start_seqno + max_size-1, hr-1) : hr-1;
forEach(start_seqno, to, missing);
return missing.getMissingElements(); return missing.getMissingElements();
} }
finally { finally {
Expand Down Expand Up @@ -859,8 +860,8 @@ protected class Missing implements Visitor<T> {
protected final int max_num_msgs; protected final int max_num_msgs;
protected int num_msgs; protected int num_msgs;


protected Missing(long start, int capacity, int max_number_of_msgs) { protected Missing(long start, int max_number_of_msgs) {
missing_elements=new SeqnoList(capacity, start); missing_elements=new SeqnoList(max_number_of_msgs, start);
this.max_num_msgs=max_number_of_msgs; this.max_num_msgs=max_number_of_msgs;
} }


Expand Down
44 changes: 43 additions & 1 deletion tests/junit-functional/org/jgroups/tests/TableTest.java
Expand Up @@ -955,9 +955,51 @@ public void testGetMissingWithMaxSize() {
assert missing.size() == 25; assert missing.size() == 25;


missing=buf.getMissing(10); missing=buf.getMissing(10);
assert missing.size() == 10; assert missing.size() == 5;

missing=buf.getMissing(200);
assert missing.size() == 25;
}


public void testGetMissingWithMaxBundleSize() {
final int max_bundle_size=64000, missing_msgs=1_000_000;
final int max_xmit_req_size=(max_bundle_size -50) * Global.LONG_SIZE;
Table<Integer> table=new Table<>(10, 1000, 0);
table.add(0, 0);
table.add(missing_msgs, missing_msgs);
System.out.println("table = " + table);

SeqnoList missing=table.getMissing(max_xmit_req_size);
System.out.println("missing = " + missing);

int serialized_size=missing.serializedSize();
assert serialized_size <= max_bundle_size :
String.format("serialized size of %d needs to be less than max_bundle_size of %d bytes", serialized_size, max_bundle_size);
} }


public void testGetMissingWithMaxBundleSize2() {
final int max_bundle_size=64000, missing_msgs=2_000_000;
final int max_xmit_req_size=(max_bundle_size -50) * Global.LONG_SIZE;
Table<Integer> table=new Table<>(10, 1000, 0);
for(int i=0; i < missing_msgs/2; i++)
table.add(i, i);

table.add(missing_msgs, missing_msgs);
System.out.println("table = " + table);

SeqnoList missing=table.getMissing(max_xmit_req_size);
System.out.println("missing = " + missing);

int serialized_size=missing.serializedSize();
assert serialized_size <= max_bundle_size :
String.format("serialized size of %d needs to be less than max_bundle_size of %d bytes", serialized_size, max_bundle_size);

int limit=missing_msgs/2 + max_xmit_req_size;
for(long l: missing) {
assert l >= missing_msgs/2 && l < limit;
}
}




public static void testGetMissingLast() { public static void testGetMissingLast() {
Expand Down

0 comments on commit 416f3c7

Please sign in to comment.