use of com.swiftmq.impl.store.standard.log.DeleteLogAction 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);
}
use of com.swiftmq.impl.store.standard.log.DeleteLogAction in project swiftmq-ce by iitsoftware.
the class QueueIndex method remove.
public MessagePageReference remove(QueueIndexEntry indexEntry) throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, indexEntry=" + indexEntry);
remove(indexEntry.getKey());
Integer rootPageNo = Integer.valueOf(indexEntry.getRootPageNo());
MessagePageReference ref = ctx.referenceMap.getReference(rootPageNo, false);
if (ref != null)
ref = ref.decRefCountAndMarkActive();
if (ref == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, indexEntry=" + indexEntry + ", no more refs, REMOVE message");
ctx.referenceMap.removeReference(rootPageNo);
MessagePage mp = new MessagePage(ctx.cacheManager.fetchAndPin(rootPageNo.intValue()));
int next = -1;
do {
mpList.add(mp.page);
if (mp.page.pageNo == 0) {
// This MUST NOT happen after a failover. We just ignore it.
ctx.logSwiftlet.logWarning("sys$store", toString() + "/try to delete a message page which was already deleted, ignore. indexEntry: " + indexEntry);
break;
}
byte[] bi = new byte[mp.getLength()];
System.arraycopy(mp.page.data, 0, bi, 0, bi.length);
journal.add(new DeleteLogAction(mp.page.pageNo, bi));
mp.page.dirty = true;
mp.page.empty = true;
next = mp.getNextPage();
if (next != -1)
mp = new MessagePage(ctx.cacheManager.fetchAndPin(next));
} while (next != -1);
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, indexEntry=" + indexEntry + ", ref is " + ref + ", HOLD message");
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove done, indexEntry=" + indexEntry);
return ref;
}
use of com.swiftmq.impl.store.standard.log.DeleteLogAction in project swiftmq-ce by iitsoftware.
the class RootIndex method deleteQueueIndex.
public synchronized void deleteQueueIndex(String queueName, QueueIndex queueIndex) throws Exception {
List entries = queueIndex.getEntries();
Semaphore sem = new Semaphore();
List journal = new ArrayList();
queueIndex.setJournal(journal);
List refs = new ArrayList();
for (Iterator iter = entries.iterator(); iter.hasNext(); ) {
MessagePageReference ref = queueIndex.remove((QueueIndexEntry) iter.next());
if (ref != null)
refs.add(ref);
if (journal.size() > 10000) {
long txId = ctx.transactionManager.createTxId();
CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueIndexRelease(queueIndex), refs);
ctx.recoveryManager.commit(logRecord);
sem.waitHere();
sem.reset();
journal.clear();
refs = new ArrayList();
ctx.transactionManager.removeTxId(txId);
}
}
IndexPage root = queueIndex.getIndexPage(queueIndex.getRootPageNo());
byte[] bi = new byte[root.getFirstFreePosition()];
System.arraycopy(root.getPage().data, 0, bi, 0, bi.length);
journal.add(new DeleteLogAction(root.getPage().pageNo, bi));
root.getPage().dirty = true;
root.getPage().empty = true;
setJournal(journal);
remove(queueName);
long txId = ctx.transactionManager.createTxId();
CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueRootIndexRelease(this, queueIndex), refs);
ctx.recoveryManager.commit(logRecord);
sem.waitHere();
ctx.transactionManager.removeTxId(txId);
}
use of com.swiftmq.impl.store.standard.log.DeleteLogAction in project swiftmq-ce by iitsoftware.
the class Index method remove.
/**
* @param key
*/
public void remove(Comparable key) throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, key=" + key + "...");
if (journal == null)
throw new NullPointerException("journal is null!");
IndexPage current = loadPageForKey(key);
if (current == null)
throw new Exception("remove(" + key + "): page not found!");
boolean found = false;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, before=" + current.getContent());
for (Iterator iter = current.iterator(); iter.hasNext(); ) {
IndexEntry entry = (IndexEntry) iter.next();
if (entry.isValid()) {
if (entry.getKey().equals(key)) {
iter.remove();
if (current.getNumberValidEntries() == 0) {
if (current.getPage().pageNo == rootPageNo) {
current.getPage().dirty = true;
// never delete the root
current.getPage().empty = false;
if (current.getNextPage() != -1)
moveNextToRoot(current);
} else {
byte[] bi = new byte[current.getFirstFreePosition()];
System.arraycopy(current.getPage().data, 0, bi, 0, bi.length);
journal.add(new DeleteLogAction(current.getPage().pageNo, bi));
current.getPage().dirty = true;
current.getPage().empty = true;
rechainAfterDelete(current);
}
}
found = true;
break;
}
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, found=" + found + ", after=" + current.getContent());
if (!found)
throw new Exception("remove(" + key + "): key not found in page!");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/remove, key=" + key + "...done.");
}
Aggregations