StoredDestination rc = destinations.get(tx, key); if (rc == null) { rc.orderIndex = new BTreeIndex<Long, MessageRecord>(pageFile, tx.allocate()); rc.messageIdIndex = new BTreeIndex<String, Long>(pageFile, tx.allocate()); rc.subscriptions = new BTreeIndex<String, KahaSubscriptionCommand>(pageFile, tx.allocate()); rc.subscriptionAcks = new BTreeIndex<String, Long>(pageFile, tx.allocate()); destinations.put(tx, key, rc); rc.orderIndex.setKeyMarshaller(LongMarshaller.INSTANCE); rc.orderIndex.setValueMarshaller(MessageKeysMarshaller.INSTANCE); rc.orderIndex.load(tx); Entry<Long, MessageRecord> lastEntry = rc.orderIndex.getLast(tx); if( lastEntry!=null ) { rc.nextMessageId = lastEntry.getKey()+1; rc.messageIdIndex.setKeyMarshaller(StringMarshaller.INSTANCE); rc.messageIdIndex.setValueMarshaller(LongMarshaller.INSTANCE); rc.messageIdIndex.load(tx); rc.subscriptions.setKeyMarshaller(StringMarshaller.INSTANCE); rc.subscriptions.setValueMarshaller(KahaSubscriptionCommandMarshaller.INSTANCE); rc.subscriptions.load(tx); rc.subscriptionAcks.setKeyMarshaller(StringMarshaller.INSTANCE); rc.subscriptionAcks.setValueMarshaller(LongMarshaller.INSTANCE);
synchronized public boolean containsKey(Transaction tx, Key key) throws IOException { assertLoaded(); return getRoot(tx).contains(tx, key); }
private void updateIndex(Transaction tx, KahaRemoveDestinationCommand command) throws IOException { StoredDestination sd = getStoredDestination(command.getDestination(), tx); sd.orderIndex.clear(tx); sd.orderIndex.unload(tx); tx.free(sd.orderIndex.getPageId()); sd.messageIdIndex.clear(tx); sd.messageIdIndex.unload(tx); tx.free(sd.messageIdIndex.getPageId()); if (sd.subscriptions != null) { sd.subscriptions.clear(tx); sd.subscriptions.unload(tx); tx.free(sd.subscriptions.getPageId()); sd.subscriptionAcks.clear(tx); sd.subscriptionAcks.unload(tx); tx.free(sd.subscriptionAcks.getPageId()); } String key = key(command.getDestination()); storedDestinations.remove(key); destinations.remove(tx, key); }
public void read(DataInput is) throws IOException { this.storedSchedulers = new BTreeIndex<String, LegacyJobSchedulerImpl>(pageFile, is.readLong()); this.storedSchedulers.setKeyMarshaller(StringMarshaller.INSTANCE); this.storedSchedulers.setValueMarshaller(new JobSchedulerMarshaller(this.store)); this.journalRC = new BTreeIndex<Integer, Integer>(pageFile, is.readLong()); this.journalRC.setKeyMarshaller(IntegerMarshaller.INSTANCE); this.journalRC.setValueMarshaller(IntegerMarshaller.INSTANCE); }
void remove(Transaction tx) throws IOException { defaultPriorityIndex.clear(tx); defaultPriorityIndex.unload(tx); tx.free(defaultPriorityIndex.getPageId()); if (lowPriorityIndex != null) { lowPriorityIndex.clear(tx); lowPriorityIndex.unload(tx); tx.free(lowPriorityIndex.getPageId()); } if (highPriorityIndex != null) { highPriorityIndex.clear(tx); highPriorityIndex.unload(tx); tx.free(highPriorityIndex.getPageId()); } }
StoredDestination rc = metadata.destinations.get(tx, key); if (rc == null) { rc.locationIndex = new BTreeIndex<>(pageFile, tx.allocate()); rc.messageIdIndex = new BTreeIndex<>(pageFile, tx.allocate()); rc.subscriptions = new BTreeIndex<>(pageFile, tx.allocate()); rc.subscriptionAcks = new BTreeIndex<>(pageFile, tx.allocate()); rc.ackPositions = new ListIndex<>(pageFile, tx.allocate()); rc.subLocations = new ListIndex<>(pageFile, tx.allocate()); metadata.destinations.put(tx, key, rc); rc.locationIndex.setKeyMarshaller(new LocationSizeMarshaller()); rc.locationIndex.setValueMarshaller(LongMarshaller.INSTANCE); rc.locationIndex.load(tx); rc.messageIdIndex.setKeyMarshaller(StringMarshaller.INSTANCE); rc.messageIdIndex.setValueMarshaller(LongMarshaller.INSTANCE); rc.messageIdIndex.load(tx); for (Iterator<Entry<Location, Long>> iterator = rc.locationIndex.iterator(tx); iterator.hasNext(); ) { Entry<Location, Long> entry = iterator.next(); rc.locationIndex.put(tx, entry.getKey(), entry.getValue()); rc.subscriptions.setKeyMarshaller(StringMarshaller.INSTANCE); rc.subscriptions.setValueMarshaller(KahaSubscriptionCommandMarshaller.INSTANCE); rc.subscriptions.load(tx);
/** * Removes one reference for the Journal log file indicated in the given Location value. * * The references are used to track which log files cannot be GC'd. When the reference count * on a log file reaches zero the file id is removed from the tracker and the log will be * removed on the next check point update. * * @param tx * The TX under which the update is to be performed. * @param location * The location value to update the reference count of. * * @throws IOException if an error occurs while updating the journal references table. */ protected void decrementJournalCount(Transaction tx, Location location) throws IOException { int logId = location.getDataFileId(); Integer refCount = metaData.getJournalRC().get(tx, logId); if (refCount != null) { int refCountValue = refCount; refCountValue--; if (refCountValue <= 0) { metaData.getJournalRC().remove(tx, logId); } else { metaData.getJournalRC().put(tx, logId, refCountValue); } } }
Prefixer<Key> prefixer = index.getPrefixer(); if(prefixer!=null) { separator = prefixer.getSimplePrefix(leftKeys[leftKeys.length - 1], rightKeys[0]); BTreeNode<Key,Value> rNode = this.index.createNode(tx, this); BTreeNode<Key,Value> lNode = this.index.createNode(tx, this); setBranchData(v, new long[] { lNode.getPageId(), rNode.getPageId() }); index.storeNode(tx, this, true); index.storeNode(tx, rNode, true); index.storeNode(tx, lNode, true); BTreeNode<Key,Value> rNode = this.index.createNode(tx, parent); index.storeNode(tx, this, true); index.storeNode(tx, rNode, true); parent.promoteValue(tx, separator, rNode.getPageId());
public void writePayload(BTreeNode<Key,Value> node, DataOutput os) throws IOException { // Write the keys short count = (short)node.keys.length; // cast may truncate value... if( count != node.keys.length ) { throw new IOException("Too many keys"); } os.writeShort(count); for (int i = 0; i < node.keys.length; i++) { index.getKeyMarshaller().writePayload(node.keys[i], os); } if( node.isBranch() ) { // If this is a branch... os.writeBoolean(true); for (int i = 0; i < count+1; i++) { os.writeLong(node.children[i]); } } else { // If this is a leaf os.writeBoolean(false); for (int i = 0; i < count; i++) { index.getValueMarshaller().writePayload(node.values[i], os); } os.writeLong(node.next); } }
final List<JobLocation> current = this.index.remove(tx, command.getExecutionTime()); if (current != null) { for (int i = 0; i < current.size(); i++) { current.remove(i); if (!current.isEmpty()) { this.index.put(tx, command.getExecutionTime(), current); result.setRepeat(result.getRepeat() - 1); if (this.index.containsKey(tx, command.getNextExecutionTime())) { target = this.index.remove(tx, command.getNextExecutionTime()); this.index.put(tx, command.getNextExecutionTime(), target); this.scheduleTime.newJob(); } else {
synchronized public void load(Transaction tx) throws IOException { if (loaded.compareAndSet(false, true)) { LOG.debug("loading"); if( keyMarshaller == null ) { throw new IllegalArgumentException("The key marshaller must be set before loading the BTreeIndex"); } if( valueMarshaller == null ) { throw new IllegalArgumentException("The value marshaller must be set before loading the BTreeIndex"); } final Page<BTreeNode<Key,Value>> p = tx.load(pageId, null); if( p.getType() == Page.PAGE_FREE_TYPE ) { // Need to initialize it.. BTreeNode<Key, Value> root = createNode(p, null); storeNode(tx, root, true); } } }
/** * Returns the next time that a job would be scheduled to run. * * @return time of next scheduled job to run. * * @throws IOException if an error occurs while fetching the time. */ public long getNextScheduleTime() throws IOException { Map.Entry<Long, List<LegacyJobLocation>> first = this.index.getFirst(this.store.getPageFile().tx()); return first != null ? first.getKey() : -1l; }
void getDeleteList(Transaction tx, ArrayList<Entry<Long, MessageKeys>> deletes, Long sequenceId) throws IOException { if (defaultPriorityIndex.containsKey(tx, sequenceId)) { getDeleteList(tx, deletes, defaultPriorityIndex, sequenceId); } else if (highPriorityIndex != null && highPriorityIndex.containsKey(tx, sequenceId)) { getDeleteList(tx, deletes, highPriorityIndex, sequenceId); } else if (lowPriorityIndex != null && lowPriorityIndex.containsKey(tx, sequenceId)) { getDeleteList(tx, deletes, lowPriorityIndex, sequenceId); } }
/** * Adds a reference for the journal log file pointed to by the given Location value. * * To prevent log files in the journal that still contain valid data that needs to be * kept in order to allow for recovery the logs must have active references. Each Job * scheduler should ensure that the logs are accurately referenced. * * @param tx * The TX under which the update is to be performed. * @param location * The location value to update the reference count of. * * @throws IOException if an error occurs while updating the journal references table. */ protected void incrementJournalCount(Transaction tx, Location location) throws IOException { int logId = location.getDataFileId(); Integer val = metaData.getJournalRC().get(tx, logId); int refCount = val != null ? val.intValue() + 1 : 1; metaData.getJournalRC().put(tx, logId, refCount); }
public StoredDestination readPayload(DataInput dataIn) throws IOException { StoredDestination value = new StoredDestination(); value.orderIndex = new BTreeIndex<Long, MessageRecord>(pageFile, dataIn.readLong()); value.messageIdIndex = new BTreeIndex<String, Long>(pageFile, dataIn.readLong()); if (dataIn.readBoolean()) { value.subscriptions = new BTreeIndex<String, KahaSubscriptionCommand>(pageFile, dataIn.readLong()); value.subscriptionAcks = new BTreeIndex<String, Long>(pageFile, dataIn.readLong()); } return value; }
private void addLast(TreeSet<Long> orderedSet, BTreeIndex<Long, MessageKeys> index, Transaction tx) throws IOException { if (index != null) { Entry<Long, MessageKeys> lastEntry = index.getLast(tx); if (lastEntry != null) { orderedSet.add(lastEntry.getKey()); } } }
public LastAck getLastAck(Transaction tx, StoredDestination sd, String subscriptionKey) throws IOException { return sd.subscriptionAcks.get(tx, subscriptionKey); }
public void read(DataInput is) throws IOException { this.lists = new BTreeIndex<String, PListImpl>(pageFile, is.readLong()); this.lists.setKeyMarshaller(StringMarshaller.INSTANCE); this.lists.setValueMarshaller(new PListMarshaller(this.store)); }
void remove(Transaction tx) throws IOException { defaultPriorityIndex.clear(tx); defaultPriorityIndex.unload(tx); tx.free(defaultPriorityIndex.getPageId()); if (lowPriorityIndex != null) { lowPriorityIndex.clear(tx); lowPriorityIndex.unload(tx); tx.free(lowPriorityIndex.getPageId()); } if (highPriorityIndex != null) { highPriorityIndex.clear(tx); highPriorityIndex.unload(tx); tx.free(highPriorityIndex.getPageId()); } }