On Sat, May 10, 2008 at 6:39 AM, Matthew Toseland
<toad at amphibian.dyndns.org> wrote:
> On Friday 09 May 2008 03:09, j16sdiz at freenetproject.org wrote:
>>
>> /**
>> - * Sample to take at a time
>> + * Scan all entries and try to move them
>> */
>> - private static final double SAMPLE_RATE = 0.05; // 5%
>> + private void moveOldEntry0(boolean queueItem) {
>> + newEntries = 0;
>> + oldEntries = 0;
>> + freeEntries = 0;
>> + resolvedEntries = 0;
>> + droppedEntries = 0;
>>
>> + List oldItems = null;
>> + if (queueItem) {
>> + oldItems = new ArrayList();
>> + }
>> +
>> + long maxOffset = maxOldItemOffset;
>> + maxOldItemOffset = 0;
>> + for (long offset = 0; offset <= maxOffset; offset++) {
>> + if (logDEBUG && offset % 1024 == 0) {
>> + Logger.debug(this, "Resize progress:
>> newEntries=" + newEntries + ",
> oldEntries=" + oldEntries
>> + + ", freeEntries=" +
>> freeEntries + ", resolvedEntries=" +
> resolvedEntries
>> + + ", droppedEntries=" +
>> droppedEntries);
>> + }
>> +
>> + if (shutdown)
>> + return;
>> +
>> + if (!lockEntry(offset)) //lock
>> + continue;
>> + try {
>> + Entry entry = readEntry(offset, null);
[....]
>> + } else { // if (entry.getStoreSize()
>> == prevStoreSize)
>> + // old store size entries, try
>> to move them
>> + oldEntries++;
>> + maxOldItemOffset = offset;
>> +
>> + entry.setStoreSize(storeSize);
>> + long newOffset =
>> entry.getOffset();
[....]
>> + } else if (queueItem) {
>> + // break tie
>> by moveing old item to queue
>> + if
>> (oldItems.size() * entryTotalLength < RESIZE_MEMORY) {
>> +
>> oldItems.add(newOffsetEntry);
>> + if
>> (newOffset > offset) {
>> +
>> oldEntries++; // newOffset wasn't counted count it
>> + }
>> +
>> +
>> writeEntry(entry);
>> +
>> freeOffset(offset);
>> +
>> resolvedEntries++;
>
> Where are we writing it to here? It looks like we write it to the old
> location, and then delete it?
>
"entry" need to migrate to newOffset, but newOffset is already
occupied by "newOffsetEntry", which also need migration. If
"queueItem" is true, we put "newOffsetEntry" to a queue and write
"entry" to "newOffset"