use of org.apache.samza.coordinator.data.ProcessorEntity in project samza by apache.
the class LeaderLivenessCheckScheduler method checkIfLeaderAlive.
private boolean checkIfLeaderAlive() {
String currJMV = currentJMVersion.get();
String blobJMV = blob.getJobModelVersion();
// Get the leader processor row from the table.
ProcessorEntity leader = getLeader(currJMV);
int currJMVInt = currJMV.equals(initialState) ? 0 : Integer.valueOf(currJMV);
ProcessorEntity nextLeader = Integer.valueOf(blobJMV) > currJMVInt ? getLeader(blobJMV) : null;
// Check if row hasn't been updated since 30 seconds.
boolean leaderIsAlive = leader != null && (System.currentTimeMillis() - leader.getTimestamp().getTime() < (LIVENESS_DEBOUNCE_TIME_SEC * 1000));
return leaderIsAlive || nextLeader != null;
}
use of org.apache.samza.coordinator.data.ProcessorEntity in project samza by apache.
the class TableUtils method deleteProcessorEntity.
/**
* Deletes a specified row in the processor table.
*
* Note: Table service uses optimistic locking by default. Hence, if there is an update after retrieving the entity,
* then the delete operation will fail.
*
* @param jmVersion Job model version of the processor row to be deleted.
* @param pid Unique processor ID of the processor row to be deleted.
* @param force True, to disable optimistic locking on the table. False, otherwise. Setting to false may result in
* AzureException when there is concurrent access to the table.
*
* @throws AzureException If an Azure storage service error occurred.
*/
public void deleteProcessorEntity(String jmVersion, String pid, boolean force) {
try {
TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class);
ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType();
if (force) {
entity.setEtag("*");
}
TableOperation remove = TableOperation.delete(entity);
table.execute(remove);
} catch (StorageException e) {
LOG.error("Azure storage exception while deleting processor entity with job model version: " + jmVersion + "and pid: " + pid, e);
throw new AzureException(e);
}
}
use of org.apache.samza.coordinator.data.ProcessorEntity in project samza by apache.
the class TableUtils method getActiveProcessorsList.
/**
* Gets the list of all active processors that are heartbeating to the processor table.
* @param currentJMVersion Current job model version that the processors in the application are operating on.
* @return List of ids of currently active processors in the application, retrieved from the processor table.
*/
public Set<String> getActiveProcessorsList(AtomicReference<String> currentJMVersion) {
Iterable<ProcessorEntity> tableList = getEntitiesWithPartition(currentJMVersion.get());
Set<String> activeProcessorsList = new HashSet<>();
for (ProcessorEntity entity : tableList) {
if (System.currentTimeMillis() - entity.getTimestamp().getTime() <= (LIVENESS_DEBOUNCE_TIME_SEC * 1000)) {
activeProcessorsList.add(entity.getRowKey());
}
}
Iterable<ProcessorEntity> unassignedList = getEntitiesWithPartition(initialState);
for (ProcessorEntity entity : unassignedList) {
long temp = System.currentTimeMillis() - entity.getTimestamp().getTime();
LOG.info("Time elapsed since last heartbeat: {}", temp);
if (temp <= (LIVENESS_DEBOUNCE_TIME_SEC * 1000)) {
activeProcessorsList.add(entity.getRowKey());
}
}
LOG.info("Active processors list: {}", activeProcessorsList);
return activeProcessorsList;
}
Aggregations