* itself.
*/
- Vector<Entry> getLiveEntries() {
+ Vector<Entry> getLiveEntries(boolean resize) {
Vector<Entry> liveEntries=new Vector<Entry>();
for(Entry entry: entries) {
- if (entry.isLive())
- liveEntries.add(entry);
+ if (entry.isLive()) {
+ if (!resize || entry.getType() != Entry.TypeTableStatus)
+ liveEntries.add(entry);
+ }
}
- if (seqnumlive)
+ if (seqnumlive && !resize)
liveEntries.add(new LastMessage(this, machineid, seqnum));
return liveEntries;
static final double RESIZE_THRESHOLD = 0.75;
private int resizethreshold;
private long lastliveslotseqn;
- private Random random;
+ private Random random=new Random();
public Table(String baseurl, String password, long _localmachineid) {
localmachineid=_localmachineid;
}
private void setResizeThreshold() {
- int resize_lower=(int) RESIZE_THRESHOLD * numslots;
+ int resize_lower=(int) (RESIZE_THRESHOLD * numslots);
resizethreshold=resize_lower-1+random.nextInt(numslots-resize_lower);
}
Slot s=new Slot(this, sequencenumber+1, localmachineid, buffer.getSlot(sequencenumber).getHMAC());
int newsize = 0;
if (liveslotcount > resizethreshold) {
+ System.out.print("A");
resize=true;
newsize = (int) (numslots * RESIZE_MULTIPLE);
}
-
if (resize) {
newsize = (int) (numslots * RESIZE_MULTIPLE);
if (!prevslot.isLive())
continue;
seenliveslot = true;
- Vector<Entry> liveentries = prevslot.getLiveEntries();
+ Vector<Entry> liveentries = prevslot.getLiveEntries(resize);
for(Entry liveentry:liveentries) {
if (s.hasSpace(liveentry)) {
s.addEntry(liveentry);
} else if (seqn==firstiffull) {
if (!resize) {
+ System.out.print("B");
return tryput(key, value, true);
}
}
if (!prevslot.isLive())
continue;
seenliveslot = true;
- Vector<Entry> liveentries = prevslot.getLiveEntries();
+ Vector<Entry> liveentries = prevslot.getLiveEntries(resize);
for(Entry liveentry:liveentries) {
if (s.hasSpace(liveentry))
s.addEntry(liveentry);
HashSet<Long> machineSet=new HashSet<Long>(lastmessagetable.keySet());
- initExpectedSize();
+ initExpectedSize(firstseqnum);
for(Slot slot: newslots) {
- updateExpectedSize();
processSlot(indexer, slot, acceptupdatestolocal, machineSet);
+ updateExpectedSize();
}
/* If there is a gap, check to see if the server sent us everything. */
throw new Error("Server Error: Server did not send all slots. Expected: "+expectedsize+" Received:"+numslots);
}
- private void initExpectedSize() {
- long prevslots = sequencenumber;
+ private void initExpectedSize(long firstsequencenumber) {
+ long prevslots = firstsequencenumber;
expectedsize = (prevslots < ((long) numslots))?(int) prevslots:numslots;
currmaxsize = numslots;
}