use of com.couchbase.client.core.error.IndexExistsException in project couchbase-jvm-clients by couchbase.
the class QueryChunkResponseParser method errorsToThrowable.
static CouchbaseException errorsToThrowable(final byte[] bytes, HttpResponse header, RequestContext ctx) {
int httpStatus = header != null ? header.status().code() : 0;
final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.fromJsonArray(bytes);
QueryErrorContext errorContext = new QueryErrorContext(ctx, errors, httpStatus);
if (errors.size() >= 1) {
ErrorCodeAndMessage codeAndMessage = errors.get(0);
int code = codeAndMessage.code();
String message = codeAndMessage.message();
int reasonCode = codeAndMessage.reason() != null ? (int) codeAndMessage.reason().getOrDefault("code", 0) : 0;
if (code == 3000) {
return new ParsingFailureException(errorContext);
} else if (PREPARED_ERROR_CODES.contains(code)) {
return new PreparedStatementFailureException(errorContext, RETRYABLE_PREPARED_ERROR_CODES.contains(code));
} else if (code == 4300 && message.matches("^.*index .*already exist.*")) {
return new IndexExistsException(errorContext);
} else if (code >= 4000 && code < 5000) {
return new PlanningFailureException(errorContext);
} else if (code == 12004 || code == 12016 || (code == 5000 && message.matches("^.*index .+ not found.*"))) {
return new IndexNotFoundException(errorContext);
} else if (code == 5000 && message.matches("^.*Index .*already exist.*")) {
return new IndexExistsException(errorContext);
} else if (code == 5000 && message.contains("limit for number of indexes that can be created per scope has been reached")) {
return new QuotaLimitedException(errorContext);
} else if (code >= 5000 && code < 6000) {
return new InternalServerFailureException(errorContext);
} else if (code == 12009) {
if (message.contains("CAS mismatch") || reasonCode == 12033) {
return new CasMismatchException(errorContext);
} else if (reasonCode == 17014) {
return new DocumentNotFoundException(errorContext);
} else if (reasonCode == 17012) {
return new DocumentExistsException(errorContext);
} else {
return new DmlFailureException(errorContext);
}
} else if ((code >= 10000 && code < 11000) || code == 13014) {
return new AuthenticationFailureException("Could not authenticate query", errorContext, null);
} else if ((code >= 12000 && code < 13000) || (code >= 14000 && code < 15000)) {
return new IndexFailureException(errorContext);
} else if (code == 1065) {
if (message.contains("query_context")) {
return FeatureNotAvailableException.scopeLevelQuery(ServiceType.QUERY);
}
if (message.contains("preserve_expiry")) {
return FeatureNotAvailableException.queryPreserveExpiry();
}
} else if (code == 1080) {
// engine will proactively send us a timeout and we need to convert it.
return new UnambiguousTimeoutException("Query timed out while streaming/receiving rows", new CancellationErrorContext(errorContext));
} else if (code == 1191 || code == 1192 || code == 1193 || code == 1194) {
return new RateLimitedException(errorContext);
} else if (code == 3230) {
String feature = null;
if (message.contains("Advisor") || message.contains("Advise")) {
feature = "Query Index Advisor";
} else if (message.contains("Window")) {
feature = "Query Window Functions";
}
return FeatureNotAvailableException.communityEdition(feature);
}
}
return new CouchbaseException("Unknown query error", errorContext);
}
use of com.couchbase.client.core.error.IndexExistsException in project couchbase-jvm-clients by couchbase.
the class AnalyticsChunkResponseParser method errorsToThrowable.
@Stability.Internal
static CouchbaseException errorsToThrowable(final byte[] bytes, RequestContext ctx, HttpResponseStatus httpStatus) {
int httpCode = httpStatus != null ? httpStatus.code() : 0;
final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.from(bytes);
AnalyticsErrorContext errorContext = new AnalyticsErrorContext(ctx, errors, httpCode);
if (errors.size() >= 1) {
ErrorCodeAndMessage error = errors.get(0);
// Analytics error code reference:
// https://docs.couchbase.com/server/current/analytics/error-codes.html
int code = error.code();
if (code >= 25000 && code < 26000) {
return new InternalServerFailureException(errorContext);
} else if (code >= 20000 && code < 21000) {
return new AuthenticationFailureException("Could not authenticate analytics query", errorContext, null);
} else if (code == 23000 || code == 23003) {
return new TemporaryFailureException(errorContext);
} else if (code == 23007) {
return new JobQueueFullException(errorContext);
} else if (code == 24000) {
return new ParsingFailureException(errorContext);
} else if (code == 24006) {
return new LinkNotFoundException(errorContext);
} else if (code == 24055) {
return new LinkExistsException(errorContext);
} else if (code == 24040) {
return new DatasetExistsException(errorContext);
} else if (code == 24044 || code == 24045 || code == 24025) {
return new DatasetNotFoundException(errorContext);
} else if (code == 24034) {
return new DataverseNotFoundException(errorContext);
} else if (code == 24039) {
return new DataverseExistsException(errorContext);
} else if (code == 24047) {
return new IndexNotFoundException(errorContext);
} else if (code == 24048) {
return new IndexExistsException(errorContext);
} else if (code > 24000 && code < 25000) {
return new CompilationFailureException(errorContext);
} else {
return new CouchbaseException("Unknown analytics error: " + error, errorContext);
}
}
return new CouchbaseException("Unknown analytics error", errorContext);
}
use of com.couchbase.client.core.error.IndexExistsException in project spring-data-couchbase by spring-projects.
the class CollectionAwareIntegrationTests method beforeAll.
@BeforeAll
public static void beforeAll() {
callSuperBeforeAll(new Object() {
});
ClusterEnvironment environment = environment().build();
Cluster cluster = Cluster.connect(seedNodes(), ClusterOptions.clusterOptions(authenticator()).environment(environment));
Bucket bucket = cluster.bucket(config().bucketname());
bucket.waitUntilReady(Duration.ofSeconds(5));
waitForService(bucket, ServiceType.QUERY);
waitForQueryIndexerToHaveBucket(cluster, config().bucketname());
CollectionManager collectionManager = bucket.collections();
setupScopeCollection(cluster, scopeName, collectionName, collectionManager);
setupScopeCollection(cluster, scopeName, collectionName2, collectionManager);
if (otherScope != null || otherCollection != null) {
// afterAll should be undoing the creation of scope etc
setupScopeCollection(cluster, otherScope, otherCollection, collectionManager);
}
try {
// needs an index for this N1ql Join
// create index ix2 on my_bucket(parent_id) where `_class` = 'org.springframework.data.couchbase.domain.Address';
List<String> fieldList = new ArrayList<>();
fieldList.add("parentId");
cluster.query("CREATE INDEX `parent_idx` ON default:" + bucketName() + "." + scopeName + "." + collectionName2 + "(parentId)");
} catch (IndexExistsException ife) {
LOGGER.warn("IndexFailureException occurred - ignoring: ", ife.toString());
}
Config.setScopeName(scopeName);
ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class);
// the Config class has been modified, these need to be loaded again
couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
reactiveCouchbaseTemplate = (ReactiveCouchbaseTemplate) ac.getBean(REACTIVE_COUCHBASE_TEMPLATE);
}
use of com.couchbase.client.core.error.IndexExistsException in project spring-data-couchbase by spring-projects.
the class CouchbasePersistentEntityIndexCreator method createIndex.
private void createIndex(final IndexDefinitionHolder indexToCreate) {
Cluster cluster = couchbaseOperations.getCouchbaseClientFactory().getCluster();
StringBuilder statement = new StringBuilder("CREATE INDEX `").append(indexToCreate.getIndexName()).append("` ON `").append(couchbaseOperations.getBucketName()).append("` (").append(String.join(",", indexToCreate.getIndexFields())).append(")");
if (indexToCreate.getIndexPredicate() != null && !indexToCreate.getIndexPredicate().isEmpty()) {
statement.append(" WHERE ").append(indexToCreate.getIndexPredicate());
}
try {
cluster.query(statement.toString());
} catch (IndexExistsException ex) {
// ignored on purpose, rest is propagated
LOGGER.debug("Index \"" + indexToCreate.getIndexName() + "\" already exists, ignoring.");
} catch (Exception ex) {
throw new DataIntegrityViolationException("Could not auto-create index with statement: " + statement.toString(), ex);
}
}
use of com.couchbase.client.core.error.IndexExistsException in project couchbase-jvm-clients by couchbase.
the class AnalyticsCollectionIntegrationTest method setup.
@BeforeAll
static void setup() {
cluster = Cluster.connect(seedNodes(), clusterOptions());
bucket = cluster.bucket(config().bucketname());
analytics = cluster.analyticsIndexes();
collectionManager = bucket.collections();
bucket.waitUntilReady(Duration.ofSeconds(5));
waitForService(bucket, ServiceType.ANALYTICS);
collectionManager.createScope(scopeName);
CollectionSpec collSpec = CollectionSpec.create(collectionName, scopeName);
collectionManager.createCollection(collSpec);
waitUntilCondition(() -> collectionExists(collectionManager, collSpec));
waitForQueryIndexerToHaveKeyspace(cluster, config().bucketname());
// this inserts two documents in bucket.scope.collection and creates a primary index.
// then inserts one document in bucket._default._default and creates a primary index.
cluster.query("insert into `" + config().bucketname() + "`.`" + scopeName + "`.`" + collectionName + "` (key, value ) values ( '123', { \"test\" : \"hello\" })");
insertDoc(bucket.scope(scopeName).collection(collectionName), FOO_CONTENT);
cluster.query("create primary index on `" + config().bucketname() + "`.`" + scopeName + "`.`" + collectionName + "`");
insertDoc(bucket.defaultCollection(), DEFAULT_CONTENT);
try {
cluster.query("create primary index on `" + config().bucketname() + "`.`" + "_default" + "`." + "_default");
} catch (IndexExistsException e) {
// Primary index is already created, ignore
}
delimitedDataverseName = "`" + config().bucketname() + "`.`" + scopeName + "`";
}
Aggregations