Search in sources :

Example 1 with UpdatePortionLogAction

use of com.swiftmq.impl.store.standard.log.UpdatePortionLogAction in project swiftmq-ce by iitsoftware.

the class Index method moveNextToRoot.

private void moveNextToRoot(IndexPage current) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/moveNextToRoot...");
    IndexPage next = getIndexPage(current.getNextPage());
    byte[] beforeImage = new byte[current.getFirstFreePosition()];
    System.arraycopy(current.getPage().data, 0, beforeImage, 0, beforeImage.length);
    System.arraycopy(next.getPage().data, 0, current.getPage().data, 0, next.getFirstFreePosition());
    byte[] afterImage = new byte[next.getFirstFreePosition()];
    System.arraycopy(current.getPage().data, 0, afterImage, 0, afterImage.length);
    journal.add(new UpdatePortionLogAction(current.getPage().pageNo, 0, beforeImage, afterImage));
    current.setPrevPage(-1);
    current.initValues();
    journal.add(new DeleteLogAction(next.getPage().pageNo, afterImage));
    next.getPage().dirty = true;
    next.getPage().empty = true;
    if (next.getNextPage() != -1) {
        next = getIndexPage(next.getNextPage());
        next.setPrevPage(current.getPage().pageNo);
    }
    maxPage = -1;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/moveNextToRoot...done, current=" + current);
}
Also used : DeleteLogAction(com.swiftmq.impl.store.standard.log.DeleteLogAction) UpdatePortionLogAction(com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)

Example 2 with UpdatePortionLogAction

use of com.swiftmq.impl.store.standard.log.UpdatePortionLogAction in project swiftmq-ce by iitsoftware.

the class IndexPage method remove.

public void remove() {
    byte[] bi = null;
    byte[] ai = null;
    int offset = iterPos - iterLastLength;
    // Before Image
    bi = new byte[iterLastLength];
    System.arraycopy(page.data, offset, bi, 0, bi.length);
    // mark invalid
    iterLastEntry.setValid(false);
    iterLastEntry.writeContent(page.data, offset);
    // After Image
    ai = new byte[iterLastLength];
    System.arraycopy(page.data, offset, ai, 0, ai.length);
    journal.add(new UpdatePortionLogAction(pageNo, offset, bi, ai));
    // Before Image
    bi = new byte[4];
    System.arraycopy(page.data, POS_NVALID, bi, 0, 4);
    // Action
    nValid--;
    Util.writeInt(nValid, page.data, POS_NVALID);
    page.dirty = true;
    page.empty = nValid == 0;
    if (iterLastEntry.getKey().equals(minKey)) {
        minKey = null;
        if (nValid > 0) {
            IndexEntry firstValid = getFirstValid(iterPos);
            if (firstValid != null) {
                minKey = firstValid.getKey();
            }
        }
    }
    if (iterLastEntry.getKey().equals(maxKey))
        maxKey = null;
    // After Image
    ai = new byte[4];
    System.arraycopy(page.data, POS_NVALID, ai, 0, 4);
    journal.add(new UpdatePortionLogAction(pageNo, POS_NVALID, bi, ai));
    if (page.empty) {
        // Before Image
        bi = new byte[4];
        System.arraycopy(page.data, POS_NENTRIES, bi, 0, 4);
        // Action
        nEntries = 0;
        Util.writeInt(nEntries, page.data, POS_NENTRIES);
        // After Image
        ai = new byte[4];
        System.arraycopy(page.data, POS_NENTRIES, ai, 0, 4);
        journal.add(new UpdatePortionLogAction(pageNo, POS_NENTRIES, bi, ai));
        firstFree = START_DATA;
    }
}
Also used : UpdatePortionLogAction(com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)

Example 3 with UpdatePortionLogAction

use of com.swiftmq.impl.store.standard.log.UpdatePortionLogAction in project swiftmq-ce by iitsoftware.

the class IndexPage method setNextPage.

void setNextPage(int l) {
    if (page == null)
        load();
    nextPage = l;
    byte[] bi = new byte[4];
    System.arraycopy(page.data, POS_NEXT_PAGE, bi, 0, 4);
    Util.writeInt(nextPage, page.data, POS_NEXT_PAGE);
    page.dirty = true;
    page.empty = false;
    byte[] ai = new byte[4];
    System.arraycopy(page.data, POS_NEXT_PAGE, ai, 0, 4);
    journal.add(new UpdatePortionLogAction(pageNo, POS_NEXT_PAGE, bi, ai));
}
Also used : UpdatePortionLogAction(com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)

Example 4 with UpdatePortionLogAction

use of com.swiftmq.impl.store.standard.log.UpdatePortionLogAction in project swiftmq-ce by iitsoftware.

the class IndexPage method replace.

public void replace(IndexEntry newEntry) {
    byte[] bi = null;
    byte[] ai = null;
    int offset = iterPos - iterLastLength;
    // Before Image
    bi = new byte[iterLastLength];
    System.arraycopy(page.data, offset, bi, 0, bi.length);
    // replace
    newEntry.writeContent(page.data, offset);
    iterLastEntry = newEntry;
    // After Image
    ai = new byte[iterLastLength];
    System.arraycopy(page.data, offset, ai, 0, ai.length);
    journal.add(new UpdatePortionLogAction(pageNo, offset, bi, ai));
}
Also used : UpdatePortionLogAction(com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)

Example 5 with UpdatePortionLogAction

use of com.swiftmq.impl.store.standard.log.UpdatePortionLogAction in project swiftmq-ce by iitsoftware.

the class IndexPage method addEntry.

/**
 * @param indexEntry
 */
public void addEntry(IndexEntry indexEntry) {
    if (page == null)
        load();
    if (minKey == null || maxKey == null)
        selectMinMaxKey();
    boolean isLower = maxKey == null || maxKey.compareTo(indexEntry.getKey()) > 0;
    if (minKey == null || minKey.compareTo(indexEntry.getKey()) > 0)
        minKey = indexEntry.getKey();
    if (maxKey == null || maxKey.compareTo(indexEntry.getKey()) < 0)
        maxKey = indexEntry.getKey();
    byte[] bi = null;
    byte[] ai = null;
    int offset = 0;
    if (nEntries > 0 && isLower) {
        IndexEntry insertEntry = null;
        int pos = START_DATA;
        for (int i = 0; i < nEntries; i++) {
            IndexEntry act = createIndexEntry();
            act.readContent(page.data, pos);
            if (act.isValid() && act.getKey().compareTo(indexEntry.getKey()) > 0) {
                insertEntry = act;
                break;
            }
            pos += act.getLength();
        }
        if (insertEntry != null) {
            int amount = firstFree - pos;
            offset = pos;
            byte[] b = new byte[amount + indexEntry.getLength()];
            System.arraycopy(page.data, pos, b, 0, b.length);
            bi = b;
            System.arraycopy(b, 0, page.data, pos + indexEntry.getLength(), amount);
            indexEntry.writeContent(page.data, pos);
            ai = new byte[amount + indexEntry.getLength()];
            System.arraycopy(page.data, pos, ai, 0, ai.length);
        } else {
            // Before Image
            offset = firstFree;
            bi = new byte[indexEntry.getLength()];
            System.arraycopy(page.data, firstFree, bi, 0, indexEntry.getLength());
            // Action
            indexEntry.writeContent(page.data, firstFree);
            // After Image
            ai = new byte[indexEntry.getLength()];
            System.arraycopy(page.data, firstFree, ai, 0, indexEntry.getLength());
        }
    } else {
        // Before Image
        offset = firstFree;
        bi = new byte[indexEntry.getLength()];
        System.arraycopy(page.data, firstFree, bi, 0, indexEntry.getLength());
        // Action
        indexEntry.writeContent(page.data, firstFree);
        // After Image
        ai = new byte[indexEntry.getLength()];
        System.arraycopy(page.data, firstFree, ai, 0, indexEntry.getLength());
    }
    firstFree += indexEntry.getLength();
    journal.add(new UpdatePortionLogAction(pageNo, offset, bi, ai));
    // Before Image
    bi = new byte[4];
    System.arraycopy(page.data, POS_NENTRIES, bi, 0, 4);
    // Action
    nEntries++;
    Util.writeInt(nEntries, page.data, POS_NENTRIES);
    // After Image
    ai = new byte[4];
    System.arraycopy(page.data, POS_NENTRIES, ai, 0, 4);
    journal.add(new UpdatePortionLogAction(pageNo, POS_NENTRIES, bi, ai));
    // Before Image
    bi = new byte[4];
    System.arraycopy(page.data, POS_NVALID, bi, 0, 4);
    // Action
    nValid++;
    Util.writeInt(nValid, page.data, POS_NVALID);
    // After Image
    ai = new byte[4];
    System.arraycopy(page.data, POS_NVALID, ai, 0, 4);
    journal.add(new UpdatePortionLogAction(pageNo, POS_NVALID, bi, ai));
    page.dirty = true;
    page.empty = false;
}
Also used : UpdatePortionLogAction(com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)

Aggregations

UpdatePortionLogAction (com.swiftmq.impl.store.standard.log.UpdatePortionLogAction)8 Page (com.swiftmq.impl.store.standard.cache.Page)1 DeleteLogAction (com.swiftmq.impl.store.standard.log.DeleteLogAction)1 InsertLogAction (com.swiftmq.impl.store.standard.log.InsertLogAction)1 IOException (java.io.IOException)1 UTFDataFormatException (java.io.UTFDataFormatException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1