@Test public void validateRequestsTest() { List<ReplicaId> localReplicas = clusterMap.getReplicaIds(dataNodeId); Map<ReplicaState, ReplicaId> stateToReplica = new HashMap<>(); int cnt = 0; for (ReplicaState state : EnumSet.complementOf(EnumSet.of(ReplicaState.ERROR))) { stateToReplica.put(state, localReplicas.get(cnt)); cnt++; } for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) { storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(entry.getKey()); } for (RequestOrResponseType request : EnumSet.of(RequestOrResponseType.PutRequest, RequestOrResponseType.GetRequest, RequestOrResponseType.DeleteRequest, RequestOrResponseType.TtlUpdateRequest, RequestOrResponseType.UndeleteRequest)) { for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) { if (request == RequestOrResponseType.PutRequest) { if (AmbryServerRequests.PUT_ALLOWED_STORE_STATES.contains(entry.getKey())) { assertEquals("Error code is not expected for PUT request", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false)); } else { assertEquals("Error code is not expected for PUT request", validateRequestOnStoreState ? ServerErrorCode.Temporarily_Disabled : ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false)); } } else if (AmbryServerRequests.UPDATE_REQUEST_TYPES.contains(request)) { if (AmbryServerRequests.UPDATE_ALLOWED_STORE_STATES.contains(entry.getKey())) { assertEquals("Error code is not expected for DELETE/TTL Update", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false)); } else { assertEquals("Error code is not expected for DELETE/TTL Update", validateRequestOnStoreState ? ServerErrorCode.Temporarily_Disabled : ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false)); } } else { assertEquals("Error code is not expected for GET request", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false)); } } } for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) { storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(ReplicaState.STANDBY); } }
@Override protected ServerErrorCode validateRequest(PartitionId partition, RequestOrResponseType requestType, boolean skipPartitionAndDiskAvailableCheck) { ServerErrorCode errorCode = super.validateRequest(partition, requestType, skipPartitionAndDiskAvailableCheck); if (errorCode != ServerErrorCode.No_Error) { return errorCode; } if (!skipPartitionAndDiskAvailableCheck) { ReplicaId localReplica = storeManager.getReplica(partition.toPathString()); if (localReplica != null && localReplica.getDiskId().getState() == HardwareState.UNAVAILABLE) { metrics.diskUnavailableError.inc(); return ServerErrorCode.Disk_Unavailable; } errorCode = storeManager.checkLocalPartitionStatus(partition, localReplica); switch (errorCode) { case Disk_Unavailable: metrics.diskUnavailableError.inc(); localReplica.markDiskDown(); return errorCode; case Replica_Unavailable: metrics.replicaUnavailableError.inc(); return errorCode; case Partition_Unknown: metrics.partitionUnknownError.inc(); return errorCode; } } if (requestType.equals(RequestOrResponseType.PutRequest) && partition.getPartitionState() == PartitionState.READ_ONLY) { metrics.partitionReadOnlyError.inc(); return ServerErrorCode.Partition_ReadOnly; } if (!isRequestEnabled(requestType, partition)) { metrics.temporarilyDisabledError.inc(); return ServerErrorCode.Temporarily_Disabled; } return ServerErrorCode.No_Error; }
AmbryServerRequests extends AmbryRequests { @Override protected ServerErrorCode validateRequest(PartitionId partition, RequestOrResponseType requestType, boolean skipPartitionAndDiskAvailableCheck) { ServerErrorCode errorCode = super.validateRequest(partition, requestType, skipPartitionAndDiskAvailableCheck); if (errorCode != ServerErrorCode.No_Error) { return errorCode; } if (!skipPartitionAndDiskAvailableCheck) { ReplicaId localReplica = storeManager.getReplica(partition.toPathString()); if (localReplica != null && localReplica.getDiskId().getState() == HardwareState.UNAVAILABLE) { metrics.diskUnavailableError.inc(); return ServerErrorCode.Disk_Unavailable; } errorCode = storeManager.checkLocalPartitionStatus(partition, localReplica); switch (errorCode) { case Disk_Unavailable: metrics.diskUnavailableError.inc(); localReplica.markDiskDown(); return errorCode; case Replica_Unavailable: metrics.replicaUnavailableError.inc(); return errorCode; case Partition_Unknown: metrics.partitionUnknownError.inc(); return errorCode; } } if (requestType.equals(RequestOrResponseType.PutRequest) && partition.getPartitionState() == PartitionState.READ_ONLY) { metrics.partitionReadOnlyError.inc(); return ServerErrorCode.Partition_ReadOnly; } if (!isRequestEnabled(requestType, partition)) { metrics.temporarilyDisabledError.inc(); return ServerErrorCode.Temporarily_Disabled; } return ServerErrorCode.No_Error; } }
AmbryServerRequests extends AmbryRequests { @Override protected ServerErrorCode validateRequest(PartitionId partition, RequestOrResponseType requestType, boolean skipPartitionAndDiskAvailableCheck) { ServerErrorCode errorCode = super.validateRequest(partition, requestType, skipPartitionAndDiskAvailableCheck); if (errorCode != ServerErrorCode.No_Error) { return errorCode; } if (!skipPartitionAndDiskAvailableCheck) { ReplicaId localReplica = storeManager.getReplica(partition.toPathString()); if (localReplica != null && localReplica.getDiskId().getState() == HardwareState.UNAVAILABLE) { metrics.diskUnavailableError.inc(); return ServerErrorCode.Disk_Unavailable; } errorCode = storeManager.checkLocalPartitionStatus(partition, localReplica); switch (errorCode) { case Disk_Unavailable: metrics.diskUnavailableError.inc(); localReplica.markDiskDown(); return errorCode; case Replica_Unavailable: metrics.replicaUnavailableError.inc(); return errorCode; case Partition_Unknown: metrics.partitionUnknownError.inc(); return errorCode; } } if (requestType.equals(RequestOrResponseType.PutRequest) && partition.getPartitionState() == PartitionState.READ_ONLY) { metrics.partitionReadOnlyError.inc(); return ServerErrorCode.Partition_ReadOnly; } if (!isRequestEnabled(requestType, partition)) { metrics.temporarilyDisabledError.inc(); return ServerErrorCode.Temporarily_Disabled; } return ServerErrorCode.No_Error; } AmbryServerRequests(StoreManager storeManager, RequestResponseChannel requestResponseChannel, ClusterMap clusterMap,
      DataNodeId nodeId, MetricRegistry registry, ServerMetrics serverMetrics, FindTokenHelper findTokenHelper,
      NotificationSystem operationNotification, ReplicationAPI replicationEngine, StoreKeyFactory storeKeyFactory,
      ServerConfig serverConfig, StoreKeyConverterFactory storeKeyConverterFactory, StatsManager statsManager,
      ClusterParticipant clusterParticipant); }
AmbryServerRequests extends AmbryRequests { @Override protected ServerErrorCode validateRequest(PartitionId partition, RequestOrResponseType requestType, boolean skipPartitionAndDiskAvailableCheck) { ServerErrorCode errorCode = super.validateRequest(partition, requestType, skipPartitionAndDiskAvailableCheck); if (errorCode != ServerErrorCode.No_Error) { return errorCode; } if (!skipPartitionAndDiskAvailableCheck) { ReplicaId localReplica = storeManager.getReplica(partition.toPathString()); if (localReplica != null && localReplica.getDiskId().getState() == HardwareState.UNAVAILABLE) { metrics.diskUnavailableError.inc(); return ServerErrorCode.Disk_Unavailable; } errorCode = storeManager.checkLocalPartitionStatus(partition, localReplica); switch (errorCode) { case Disk_Unavailable: metrics.diskUnavailableError.inc(); localReplica.markDiskDown(); return errorCode; case Replica_Unavailable: metrics.replicaUnavailableError.inc(); return errorCode; case Partition_Unknown: metrics.partitionUnknownError.inc(); return errorCode; } } if (requestType.equals(RequestOrResponseType.PutRequest) && partition.getPartitionState() == PartitionState.READ_ONLY) { metrics.partitionReadOnlyError.inc(); return ServerErrorCode.Partition_ReadOnly; } if (!isRequestEnabled(requestType, partition)) { metrics.temporarilyDisabledError.inc(); return ServerErrorCode.Temporarily_Disabled; } return ServerErrorCode.No_Error; } AmbryServerRequests(StoreManager storeManager, RequestResponseChannel requestResponseChannel, ClusterMap clusterMap,
      DataNodeId nodeId, MetricRegistry registry, ServerMetrics serverMetrics, FindTokenHelper findTokenHelper,
      NotificationSystem operationNotification, ReplicationAPI replicationEngine, StoreKeyFactory storeKeyFactory,
      ServerConfig serverConfig, StoreKeyConverterFactory storeKeyConverterFactory, StatsManager statsManager,
      ClusterParticipant clusterParticipant); @Override void handleAdminRequest(NetworkRequest request); }
AmbryServerRequests extends AmbryRequests { @Override protected ServerErrorCode validateRequest(PartitionId partition, RequestOrResponseType requestType, boolean skipPartitionAndDiskAvailableCheck) { ServerErrorCode errorCode = super.validateRequest(partition, requestType, skipPartitionAndDiskAvailableCheck); if (errorCode != ServerErrorCode.No_Error) { return errorCode; } if (!skipPartitionAndDiskAvailableCheck) { ReplicaId localReplica = storeManager.getReplica(partition.toPathString()); if (localReplica != null && localReplica.getDiskId().getState() == HardwareState.UNAVAILABLE) { metrics.diskUnavailableError.inc(); return ServerErrorCode.Disk_Unavailable; } errorCode = storeManager.checkLocalPartitionStatus(partition, localReplica); switch (errorCode) { case Disk_Unavailable: metrics.diskUnavailableError.inc(); localReplica.markDiskDown(); return errorCode; case Replica_Unavailable: metrics.replicaUnavailableError.inc(); return errorCode; case Partition_Unknown: metrics.partitionUnknownError.inc(); return errorCode; } } if (requestType.equals(RequestOrResponseType.PutRequest) && partition.getPartitionState() == PartitionState.READ_ONLY) { metrics.partitionReadOnlyError.inc(); return ServerErrorCode.Partition_ReadOnly; } if (!isRequestEnabled(requestType, partition)) { metrics.temporarilyDisabledError.inc(); return ServerErrorCode.Temporarily_Disabled; } return ServerErrorCode.No_Error; } AmbryServerRequests(StoreManager storeManager, RequestResponseChannel requestResponseChannel, ClusterMap clusterMap,
      DataNodeId nodeId, MetricRegistry registry, ServerMetrics serverMetrics, FindTokenHelper findTokenHelper,
      NotificationSystem operationNotification, ReplicationAPI replicationEngine, StoreKeyFactory storeKeyFactory,
      ServerConfig serverConfig, StoreKeyConverterFactory storeKeyConverterFactory, StatsManager statsManager,
      ClusterParticipant clusterParticipant); @Override void handleAdminRequest(NetworkRequest request);  }