use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class KinesisAdminClient method updatePartitionCount.
/**
* This method updates the shard count of {@param streamName} to have a final shard count of {@param newShardCount}
* If {@param blocksUntilStarted} is set to true, then this method will blocks until the resharding
* started (but not nessesary finished), otherwise, the method will returns right after issue the reshard command
*/
@Override
public void updatePartitionCount(String streamName, int newShardCount, boolean blocksUntilStarted) {
int originalShardCount = getStreamPartitionCount(streamName);
if (originalShardCount == newShardCount) {
return;
}
UpdateShardCountRequest updateShardCountRequest = new UpdateShardCountRequest();
updateShardCountRequest.setStreamName(streamName);
updateShardCountRequest.setTargetShardCount(newShardCount);
updateShardCountRequest.setScalingType(ScalingType.UNIFORM_SCALING);
UpdateShardCountResult updateShardCountResult = amazonKinesis.updateShardCount(updateShardCountRequest);
if (updateShardCountResult.getSdkHttpMetadata().getHttpStatusCode() != 200) {
throw new ISE("Cannot update stream's shard count for integration test");
}
if (blocksUntilStarted) {
// Wait until the resharding started (or finished)
ITRetryUtil.retryUntil(() -> {
int updatedShardCount = getStreamPartitionCount(streamName);
return verifyStreamStatus(streamName, StreamStatus.ACTIVE, StreamStatus.UPDATING) && updatedShardCount != originalShardCount;
}, true, // higher value to avoid exceeding kinesis TPS limit
300, 100, "Kinesis stream resharding to start (or finished)");
}
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class HttpUtil method makeRequestWithExpectedStatus.
public static StatusResponseHolder makeRequestWithExpectedStatus(HttpClient httpClient, HttpMethod method, String url, @Nullable byte[] content, HttpResponseStatus expectedStatus) {
try {
Request request = new Request(method, new URL(url));
if (content != null) {
request.setContent(MediaType.APPLICATION_JSON, content);
}
int retryCount = 0;
StatusResponseHolder response;
while (true) {
response = httpClient.go(request, RESPONSE_HANDLER).get();
if (!response.getStatus().equals(expectedStatus)) {
String errMsg = StringUtils.format("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
// it can take time for the auth config to propagate, so we retry
if (retryCount > NUM_RETRIES) {
throw new ISE(errMsg);
} else {
LOG.error(errMsg);
LOG.error("retrying in 3000ms, retryCount: " + retryCount);
retryCount++;
Thread.sleep(DELAY_FOR_RETRIES_MS);
}
} else {
break;
}
}
return response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class ByteBufferMinMaxOffsetHeap method verifyIndex.
private boolean verifyIndex(int i) {
Comparator comparator = isEvenLevel(i) ? minComparator : maxComparator;
int offset = buf.getInt(i * Integer.BYTES);
int lcIdx = getLeftChildIndex(i);
if (lcIdx < heapSize) {
int leftChildOffset = buf.getInt(lcIdx * Integer.BYTES);
if (comparator.compare(offset, leftChildOffset) > 0) {
throw new ISE("Left child val[%d] at idx[%d] is less than val[%d] at idx[%d]", leftChildOffset, lcIdx, offset, i);
}
}
int rcIdx = getRightChildIndex(i);
if (rcIdx < heapSize) {
int rightChildOffset = buf.getInt(rcIdx * Integer.BYTES);
if (comparator.compare(offset, rightChildOffset) > 0) {
throw new ISE("Right child val[%d] at idx[%d] is less than val[%d] at idx[%d]", rightChildOffset, rcIdx, offset, i);
}
}
if (i > 0) {
int parentIdx = getParentIndex(i);
int parentOffset = buf.getInt(parentIdx * Integer.BYTES);
if (comparator.compare(offset, parentOffset) > 0) {
throw new ISE("Parent val[%d] at idx[%d] is less than val[%d] at idx[%d]", parentOffset, parentIdx, offset, i);
}
}
if (i > 2) {
int gpIdx = getGrandparentIndex(i);
int gpOffset = buf.getInt(gpIdx * Integer.BYTES);
if (comparator.compare(gpOffset, offset) > 0) {
throw new ISE("Grandparent val[%d] at idx[%d] is less than val[%d] at idx[%d]", gpOffset, gpIdx, offset, i);
}
}
return true;
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class ByteBufferMinMaxOffsetHeap method removeMin.
public int removeMin() {
if (heapSize < 1) {
throw new ISE("Empty heap");
}
int minOffset = buf.getInt(0);
if (heapIndexUpdater != null) {
heapIndexUpdater.updateHeapIndexForOffset(minOffset, -1);
}
if (heapSize == 1) {
heapSize--;
return minOffset;
}
int lastIndex = heapSize - 1;
int lastOffset = buf.getInt(lastIndex * Integer.BYTES);
heapSize--;
buf.putInt(0, lastOffset);
if (heapIndexUpdater != null) {
heapIndexUpdater.updateHeapIndexForOffset(lastOffset, 0);
}
Comparator comparator = isEvenLevel(0) ? minComparator : maxComparator;
siftDown(comparator, 0);
return minOffset;
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class ByteBufferMinMaxOffsetHeap method removeMax.
public int removeMax() {
int maxOffset;
if (heapSize < 1) {
throw new ISE("Empty heap");
}
if (heapSize == 1) {
heapSize--;
maxOffset = buf.getInt(0);
if (heapIndexUpdater != null) {
heapIndexUpdater.updateHeapIndexForOffset(maxOffset, -1);
}
return maxOffset;
}
// index of max must be 1, just remove it and shrink the heap
if (heapSize == 2) {
heapSize--;
maxOffset = buf.getInt(Integer.BYTES);
if (heapIndexUpdater != null) {
heapIndexUpdater.updateHeapIndexForOffset(maxOffset, -1);
}
return maxOffset;
}
int maxIndex = findMaxElementIndex();
maxOffset = buf.getInt(maxIndex * Integer.BYTES);
int lastIndex = heapSize - 1;
int lastOffset = buf.getInt(lastIndex * Integer.BYTES);
heapSize--;
buf.putInt(maxIndex * Integer.BYTES, lastOffset);
if (heapIndexUpdater != null) {
heapIndexUpdater.updateHeapIndexForOffset(maxOffset, -1);
heapIndexUpdater.updateHeapIndexForOffset(lastOffset, maxIndex);
}
Comparator comparator = isEvenLevel(maxIndex) ? minComparator : maxComparator;
siftDown(comparator, maxIndex);
return maxOffset;
}
Aggregations