Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,837 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/src/main/java/com/datastax/oss/driver/api/core/RequestThrottlingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.core; | ||
|
||
/** | ||
* Thrown if the session uses a request throttler, and it didn't allow the current request to | ||
* execute. | ||
* | ||
* <p>This can happen either when the session is overloaded, or at shutdown for requests that had | ||
* been enqueued. | ||
*/ | ||
public class RequestThrottlingException extends DriverException { | ||
|
||
public RequestThrottlingException(String message) { | ||
super(message, null, true); | ||
} | ||
|
||
@Override | ||
public DriverException copy() { | ||
return new RequestThrottlingException(getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...java/com/datastax/oss/driver/internal/core/adminrequest/ThrottledAdminRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.internal.core.adminrequest; | ||
|
||
import com.datastax.oss.driver.api.core.DriverTimeoutException; | ||
import com.datastax.oss.driver.api.core.RequestThrottlingException; | ||
import com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric; | ||
import com.datastax.oss.driver.internal.core.channel.DriverChannel; | ||
import com.datastax.oss.driver.internal.core.metrics.SessionMetricUpdater; | ||
import com.datastax.oss.driver.internal.core.session.throttling.RequestThrottler; | ||
import com.datastax.oss.driver.internal.core.session.throttling.Throttled; | ||
import com.datastax.oss.protocol.internal.Message; | ||
import java.nio.ByteBuffer; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class ThrottledAdminRequestHandler extends AdminRequestHandler implements Throttled { | ||
|
||
private final long startTimeNanos; | ||
private final RequestThrottler throttler; | ||
private final SessionMetricUpdater metricUpdater; | ||
|
||
public ThrottledAdminRequestHandler( | ||
DriverChannel channel, | ||
Message message, | ||
Map<String, ByteBuffer> customPayload, | ||
Duration timeout, | ||
RequestThrottler throttler, | ||
SessionMetricUpdater metricUpdater, | ||
String logPrefix, | ||
String debugString) { | ||
super(channel, message, customPayload, timeout, logPrefix, debugString); | ||
this.startTimeNanos = System.nanoTime(); | ||
this.throttler = throttler; | ||
this.metricUpdater = metricUpdater; | ||
} | ||
|
||
@Override | ||
public CompletionStage<AdminResult> start() { | ||
// Don't write request yet, wait for green light from throttler | ||
throttler.register(this); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void onThrottleReady(boolean wasDelayed) { | ||
if (wasDelayed) { | ||
metricUpdater.updateTimer( | ||
DefaultSessionMetric.THROTTLING_DELAY, | ||
System.nanoTime() - startTimeNanos, | ||
TimeUnit.NANOSECONDS); | ||
} | ||
super.start(); | ||
} | ||
|
||
@Override | ||
public void onThrottleFailure(RequestThrottlingException error) { | ||
metricUpdater.incrementCounter(DefaultSessionMetric.THROTTLING_ERRORS); | ||
setFinalError(error); | ||
} | ||
|
||
@Override | ||
protected boolean setFinalResult(AdminResult result) { | ||
boolean wasSet = super.setFinalResult(result); | ||
if (wasSet) { | ||
throttler.signalSuccess(this); | ||
} | ||
return wasSet; | ||
} | ||
|
||
@Override | ||
protected boolean setFinalError(Throwable error) { | ||
boolean wasSet = super.setFinalError(error); | ||
if (wasSet) { | ||
if (error instanceof DriverTimeoutException) { | ||
throttler.signalTimeout(this); | ||
} else if (!(error instanceof RequestThrottlingException)) { | ||
throttler.signalError(this, error); | ||
} | ||
} | ||
return wasSet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.