-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
171 additions
and
50 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
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
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
21 changes: 21 additions & 0 deletions
21
src/main/java/net/iponweb/disthene/service/store/CustomDriverOption.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,21 @@ | ||
package net.iponweb.disthene.service.store; | ||
|
||
import com.datastax.oss.driver.api.core.config.DriverOption; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
public enum CustomDriverOption implements DriverOption { | ||
CUSTOM_NUMBER_OF_RETRIES("custom.retry-policy.max-retries"), | ||
; | ||
|
||
private final String path; | ||
|
||
CustomDriverOption(String path) { | ||
this.path = path; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getPath() { | ||
return path; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/net/iponweb/disthene/service/store/CustomRetryPolicy.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,43 @@ | ||
package net.iponweb.disthene.service.store; | ||
|
||
import com.datastax.oss.driver.api.core.ConsistencyLevel; | ||
import com.datastax.oss.driver.api.core.context.DriverContext; | ||
import com.datastax.oss.driver.api.core.retry.RetryDecision; | ||
import com.datastax.oss.driver.api.core.servererrors.WriteType; | ||
import com.datastax.oss.driver.api.core.session.Request; | ||
import com.datastax.oss.driver.internal.core.retry.DefaultRetryPolicy; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CustomRetryPolicy extends DefaultRetryPolicy { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DefaultRetryPolicy.class); | ||
|
||
private final String logPrefix; | ||
private final int maxRetries; | ||
|
||
private static final int DEFAULT_MAX_RETRIES = 10; | ||
|
||
public CustomRetryPolicy(DriverContext context, String profileName) { | ||
super(context, profileName); | ||
this.logPrefix = (context != null ? context.getSessionName() : null) + "|" + profileName; | ||
|
||
maxRetries = context != null ? context.getConfig().getProfile(profileName).getInt(CustomDriverOption.CUSTOM_NUMBER_OF_RETRIES, DEFAULT_MAX_RETRIES) : DEFAULT_MAX_RETRIES; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public RetryDecision onWriteTimeout(@NonNull Request request, @NonNull ConsistencyLevel cl, @NonNull WriteType writeType, int blockFor, int received, int retryCount) { | ||
RetryDecision decision = | ||
(retryCount <= maxRetries) | ||
? RetryDecision.RETRY_NEXT | ||
: RetryDecision.RETHROW; | ||
|
||
if (decision == RetryDecision.RETRY_NEXT && LOG.isTraceEnabled()) { | ||
LOG.info( | ||
RETRYING_ON_WRITE_TIMEOUT, logPrefix, cl, writeType, blockFor, received, retryCount); | ||
} | ||
return decision; | ||
} | ||
} |
Oops, something went wrong.