Search in sources :

Example 1 with BackupAwareOperation

use of com.hazelcast.spi.BackupAwareOperation in project hazelcast by hazelcast.

the class BackpressureRegulator method isSyncForced.

/**
     * Checks if a sync is forced for the given BackupAwareOperation.
     * <p/>
     * Once and a while for every BackupAwareOperation with one or more async backups, these async backups are transformed
     * into a sync backup.
     *
     * For {@link com.hazelcast.spi.UrgentSystemOperation} no sync will be forced.
     *
     * @param backupAwareOp The BackupAwareOperation to check.
     * @return true if a sync needs to be forced, false otherwise.
     */
boolean isSyncForced(BackupAwareOperation backupAwareOp) {
    if (disabled) {
        return false;
    }
    if (backupAwareOp.getPartitionId() < 0) {
        throw new IllegalArgumentException("A BackupAwareOperation can't have a negative partitionId, " + backupAwareOp);
    }
    // if there are no asynchronous backups, there is nothing to regulate.
    if (backupAwareOp.getAsyncBackupCount() == 0) {
        return false;
    }
    Operation op = (Operation) backupAwareOp;
    // we never apply back-pressure on urgent operations.
    if (op.isUrgent()) {
        return false;
    }
    int index = op.getPartitionId() * INTS_PER_CACHE_LINE;
    int oldSyncDelay = syncDelays[index];
    if (oldSyncDelay == 1) {
        int newSyncDelay = randomSyncDelay();
        syncDelays[index] = newSyncDelay;
        return true;
    }
    syncDelays[index] = oldSyncDelay - 1;
    return false;
}
Also used : Operation(com.hazelcast.spi.Operation) BackupAwareOperation(com.hazelcast.spi.BackupAwareOperation)

Aggregations

BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)1 Operation (com.hazelcast.spi.Operation)1