/** * * @param indexFig config * @param aliasPrefix alias prefix, e.g. app_id etc.. */ public ManagementIndexAlias(IndexFig indexFig,String aliasPrefix) { this.writeAlias = aliasPrefix + "_write_" + indexFig.getAliasPostfix(); this.readAlias = aliasPrefix + "_read_" + indexFig.getAliasPostfix(); }
@Override public int getNumberOfReplicas() { return indexFig.getNumberOfReplicas(); }
@Override public int getNumberOfShards() { return indexFig.getNumberOfShards(); }
@Test public void testNoViolations() throws Throwable { when ( fig.getQueryBreakerErrorSortPredicateCount() ).thenReturn( 5 ); when ( fig.getQueryBreakerErrorOperandCount() ).thenReturn( 5 ); when ( fig.getQueryBreakerErrorIndexSizeBytes() ).thenReturn( 5L ); when ( fig.getQueryBreakerErrorCollectionSizeBytes() ).thenReturn( 5L ); ParsedQuery parsedQuery; List<Map<String,Object>> violations; parsedQuery = ParsedQueryBuilder.build("select * order by created asc"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); parsedQuery = ParsedQueryBuilder.build("select name='value' order by created asc"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); parsedQuery = ParsedQueryBuilder.build("where name='value'"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); }
.buffer(250, TimeUnit.MILLISECONDS, indexFig.getIndexBatchSize())
@Test public void collectionSizeViolation() throws Throwable { // the sort violation is only tripped when the collection size warning is tripped when ( fig.getQueryBreakerErrorCollectionSizeBytes() ).thenReturn( 0L ); ParsedQuery parsedQuery = ParsedQueryBuilder.build("select created order by created asc"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_large_collection); if(!violationExists){ fail("Collection Size Violation should be present"); } }
if (parsedQuery.isDirectQuery() && parsedQuery.getDirectQueryItemCount() > indexFig.directQueryMaxItems()) { throw new TooManyDirectEntitiesException(parsedQuery.getDirectQueryItemCount(), indexFig.directQueryMaxItems()); if(indexFig.enforceQueryBreaker() && violations.size() > 0){ throw new QueryAnalyzerEnforcementException(violations, parsedQuery.getOriginalQuery()); }else if (violations.size() > 0){
final int errorPredicateCount = indexFig.getQueryBreakerErrorSortPredicateCount(); final int errorOperandCount = indexFig.getQueryBreakerErrorOperandCount(); final long errorCollectionSizeBytes = indexFig.getQueryBreakerErrorCollectionSizeBytes(); final long errorIndexSizeBytes = indexFig.getQueryBreakerErrorIndexSizeBytes();
@Override public Observable<IndexOperationMessage> indexEntity( final ApplicationScope applicationScope, final Entity entity ) { //bootstrap the lower modules from their caches final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); final EntityIndex ei = entityIndexFactory.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope)); final Id entityId = entity.getId(); //we always index in the target scope final Observable<Edge> edgesToTarget = edgesObservable.edgesToTarget( gm, entityId, true); //we may have to index we're indexing from source->target here final Observable<IndexEdge> sourceEdgesToIndex = edgesToTarget.map( edge -> generateScopeFromSource( edge ) ); //do our observable for batching //try to send a whole batch if we can final Observable<IndexOperationMessage> batches = sourceEdgesToIndex .buffer(indexFig.getIndexBatchSize() ) //map into batches based on our buffer size .flatMap( buffer -> Observable.from( buffer ) //collect results into a single batch .collect( () -> ei.createBatch(), ( batch, indexEdge ) -> { if (logger.isDebugEnabled()) { logger.debug("adding edge {} to batch for entity {}", indexEdge, entity); } final Optional<Set<String>> fieldsToIndex = getFilteredStringObjectMap( indexEdge ); batch.index( indexEdge, entity ,fieldsToIndex); } ) //return the future from the batch execution .map( batch -> batch.build() ) ); return ObservableTimer.time( batches, indexTimer ); }
/** * * @param indexFig config * @param aliasPrefix alias prefix, e.g. app_id etc.. */ public TestIndexAlias(IndexFig indexFig,String aliasPrefix) { this.writeAlias = aliasPrefix + "_write_" + indexFig.getAliasPostfix(); this.readAlias = aliasPrefix + "_read_" + indexFig.getAliasPostfix(); }
final int expectedSize = ( int ) Math.ceil( ( (double)edgeCount + 1 ) / indexFig.getIndexBatchSize() );
@Override public int getNumberOfShards() { return indexFig.getNumberOfShards(); }
@Override public int getNumberOfReplicas() { return indexFig.getNumberOfReplicas(); }
/** * * @param indexFig config * @param aliasPrefix alias prefix, e.g. app_id etc.. */ public ApplicationIndexAlias(IndexFig indexFig, ApplicationScope applicationScope, String aliasPrefix) { this.writeAlias = aliasPrefix + "_" + applicationScope.getApplication().getUuid() + "_write_" + indexFig.getAliasPostfix(); this.readAlias = aliasPrefix + "_" + applicationScope.getApplication().getUuid() + "_read_" + indexFig.getAliasPostfix(); }
@Test public void applicationAliasName(){ IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope); String applicationId = applicationScope.getApplication().getUuid().toString().toLowerCase(); assertEquals( indexLocationStrategy.getAlias().getReadAlias(), clusterName +"_"+ applicationId + "_read_" + indexFig.getAliasPostfix() ); assertEquals( indexLocationStrategy.getAlias().getWriteAlias(), clusterName +"_"+ applicationId + "_write_" + indexFig.getAliasPostfix() ); }
@Test public void managementAliasName(){ IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope); String managementAppIndexName = indexProcessorFig.getManagementAppIndexName(); assertEquals( indexLocationStrategy.getAlias().getReadAlias(), clusterName + "_" + keyspaceName + "_" + managementAppIndexName + "_read_" + indexFig.getAliasPostfix() ); assertEquals( indexLocationStrategy.getAlias().getWriteAlias(), clusterName + "_" + keyspaceName + "_" + managementAppIndexName + "_write_" + indexFig.getAliasPostfix() ); }