Search in sources :

Example 6 with ProcessorEntity

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;
}
Also used : ProcessorEntity(org.apache.samza.coordinator.data.ProcessorEntity)

Example 7 with ProcessorEntity

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);
    }
}
Also used : AzureException(org.apache.samza.AzureException) TableOperation(com.microsoft.azure.storage.table.TableOperation) ProcessorEntity(org.apache.samza.coordinator.data.ProcessorEntity) StorageException(com.microsoft.azure.storage.StorageException)

Example 8 with ProcessorEntity

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;
}
Also used : ProcessorEntity(org.apache.samza.coordinator.data.ProcessorEntity) HashSet(java.util.HashSet)

Aggregations

ProcessorEntity (org.apache.samza.coordinator.data.ProcessorEntity)8 StorageException (com.microsoft.azure.storage.StorageException)4 TableOperation (com.microsoft.azure.storage.table.TableOperation)4 AzureException (org.apache.samza.AzureException)3 HashSet (java.util.HashSet)2