/** * start failed -decrement the starting flag. * @return true if the node is now available */ public synchronized boolean onStartFailed() { decStarting(); ++startFailed; return containerCompleted(false, ContainerOutcome.Failed); }
/** * Count the number of active role instances on this node * @param role role index * @return 0 if there are none, otherwise the #of nodes that are running and * not being released already. */ public int getActiveRoleInstances(int role) { NodeEntry nodeEntry = get(role); return (nodeEntry != null ) ? nodeEntry.getActive() : 0; }
/** * run through each entry; gc'ing & removing old ones that don't have * a recent failure count (we care about those) * @param absoluteTime age in millis * @return true if there are still entries left */ public synchronized boolean purgeUnusedEntries(long absoluteTime) { boolean active = false; ListIterator<NodeEntry> entries = nodeEntries.listIterator(); while (entries.hasNext()) { NodeEntry entry = entries.next(); if (entry.notUsedSince(absoluteTime) && entry.getFailedRecently() == 0) { entries.remove(); } else { active = true; } } return active; }
public synchronized void onStartCompleted() { decStarting(); incLive(); }
/** * Build a {@link NodeEntryRecord} from a node entry; include whether * the node is in use and when it was last used. * @param entry entry count * @param role role index * @param hostname name * @return the record */ private NodeEntryRecord build(NodeEntry entry, int role, String hostname) { NodeEntryRecord record = new NodeEntryRecord( hostname, role, entry.getLive() > 0, entry.getLastUsed() ); return record; }
/** * Mark a container finished; if it was released then that is treated * differently. history is {@code touch()}-ed * * * @param container completed container * @param wasReleased was the container released? * @param shortLived was the container short lived? * @param outcome * @return true if the node was queued */ protected synchronized boolean markContainerFinished(Container container, boolean wasReleased, boolean shortLived, ContainerOutcome outcome) { NodeEntry nodeEntry = getOrCreateNodeEntry(container); log.info("Finished container for node {}, released={}, shortlived={}", nodeEntry.rolePriority, wasReleased, shortLived); boolean available; if (shortLived) { nodeEntry.onStartFailed(); available = false; } else { available = nodeEntry.containerCompleted(wasReleased, outcome); maybeQueueNodeForWork(container, nodeEntry, available); } touch(); return available; }
decLive(); return isAvailable();
for (NodeEntryRecord nodeEntryRecord : loadedRoleHistory.records) { Integer roleId = nodeEntryRecord.getRole(); NodeEntry nodeEntry = new NodeEntry(roleId); nodeEntry.setLastUsed(nodeEntryRecord.getLastUsed()); if (nodeEntryRecord.getActive()) { nodeEntry.setLastUsed(saved);
/** * Return true if the node is not busy, and it * has not been used since the absolute time * @param absoluteTime time * @return true if the node could be cleaned up */ public synchronized boolean notUsedSince(long absoluteTime) { return isAvailable() && lastUsed < absoluteTime; }
@Override public int compare(NodeInstance o1, NodeInstance o2) { NodeEntry left = o1.get(role); NodeEntry right = o2.get(role); long ageL = left != null ? left.getLastUsed() : -1; long ageR = right != null ? right.getLastUsed() : -1; return comparator.compare(ageL, ageR); } }
/** * Query for a node being considered unreliable * @param role role key * @param threshold threshold above which a node is considered unreliable * @return true if the node is considered unreliable */ public boolean isConsideredUnreliable(int role, int threshold) { NodeEntry entry = get(role); return entry != null && entry.getFailedRecently() > threshold; }
/** * Count the number of live role instances on this node * @param role role index * @return 0 if there are none, otherwise the #of nodes that are running */ public int getLiveRoleInstances(int role) { NodeEntry nodeEntry = get(role); return (nodeEntry != null ) ? nodeEntry.getLive() : 0; }
/** * Get the entry for a role -if present * @param role role index * @return the entry * @throws ArrayIndexOutOfBoundsException if the role is out of range */ public synchronized NodeEntry getOrCreate(int role) { NodeEntry entry = get(role); if (entry == null) { entry = new NodeEntry(role); nodeEntries.add(entry); } return entry; }
public synchronized void onStartCompleted() { decStarting(); incLive(); }
/** * Build a {@link NodeEntryRecord} from a node entry; include whether * the node is in use and when it was last used. * @param entry entry count * @param role role index * @param hostname name * @return the record */ private NodeEntryRecord build(NodeEntry entry, int role, String hostname) { NodeEntryRecord record = new NodeEntryRecord( hostname, role, entry.getLive() > 0, entry.getLastUsed() ); return record; }
/** * Mark a container finished; if it was released then that is treated * differently. history is {@code touch()}-ed * * * @param container completed container * @param wasReleased was the container released? * @param shortLived was the container short lived? * @param outcome * @return true if the node was queued */ protected synchronized boolean markContainerFinished(Container container, boolean wasReleased, boolean shortLived, ContainerOutcome outcome) { NodeEntry nodeEntry = getOrCreateNodeEntry(container); log.info("Finished container for node {}, released={}, shortlived={}", nodeEntry.rolePriority, wasReleased, shortLived); boolean available; if (shortLived) { nodeEntry.onStartFailed(); available = false; } else { available = nodeEntry.containerCompleted(wasReleased, outcome); maybeQueueNodeForWork(container, nodeEntry, available); } touch(); return available; }
decLive(); return isAvailable();
for (NodeEntryRecord nodeEntryRecord : loadedRoleHistory.records) { Integer roleId = nodeEntryRecord.getRole(); NodeEntry nodeEntry = new NodeEntry(roleId); nodeEntry.setLastUsed(nodeEntryRecord.getLastUsed()); if (nodeEntryRecord.getActive()) { nodeEntry.setLastUsed(saved);
/** * Return true if the node is not busy, and it * has not been used since the absolute time * @param absoluteTime time * @return true if the node could be cleaned up */ public synchronized boolean notUsedSince(long absoluteTime) { return isAvailable() && lastUsed < absoluteTime; }
@Override public int compare(NodeInstance o1, NodeInstance o2) { NodeEntry left = o1.get(role); NodeEntry right = o2.get(role); long ageL = left != null ? left.getLastUsed() : -1; long ageR = right != null ? right.getLastUsed() : -1; return comparator.compare(ageL, ageR); } }