public boolean isBootstrapping() { if ( getCause() instanceof BadRequestException ) { BadRequestException bre = (BadRequestException)getCause(); String msg = bre.getMessage(); if ( (msg.contains("Keyspace") && msg.contains( "does not exist" )) || msg.contains("unconfigured columnfamily")) { return true; } } return false; }
if ( throwable instanceof CollectionRuntimeException ) { CollectionRuntimeException cre = (CollectionRuntimeException) throwable; isBootstrapping = cre.isBootstrapping(); } else { isBootstrapping = false;
private void confirmUniqueFieldsAkka( MvccEntity mvccEntity, UUID version, ApplicationScope scope, String region ) { final Entity entity = mvccEntity.getEntity().get(); try { akkaUvService.confirmUniqueValues( scope, entity, version, region ); } catch (UniqueValueException e) { Map<String, Field> violations = new HashMap<>(); violations.put( e.getField().getName(), e.getField() ); throw new WriteUniqueVerifyException( mvccEntity, scope, violations ); } } }
private void handleWriteUniqueVerifyException( Entity entity, WriteUniqueVerifyException wuve ) throws DuplicateUniquePropertyExistsException { // we may have multiple conflicts, but caller expects only one Map<String, Field> violiations = wuve.getViolations(); if ( violiations != null ) { Field conflict = violiations.get( violiations.keySet().iterator().next() ); throw new DuplicateUniquePropertyExistsException( entity.getType(), conflict.getName(), conflict.getValue() ); } else { throw new DuplicateUniquePropertyExistsException( entity.getType(), "Unknown property name", "Unknown property value" ); } }
public void call( final Throwable t ) { if ( t instanceof CollectionRuntimeException ) { CollectionRuntimeException cre = ( CollectionRuntimeException ) t; final MvccEntity mvccEntity = cre.getEntity(); final ApplicationScope scope = cre.getApplicationScope(); // one batch to handle rollback MutationBatch rollbackMb = null; final BatchStatement uniqueDeleteBatch = new BatchStatement(); final Optional<Entity> entity = mvccEntity.getEntity(); if ( entity.isPresent() ) { for ( final Field field : entity.get().getFields() ) { // if it's unique, add its deletion to the rollback batch if ( field.isUnique() ) { UniqueValue toDelete = new UniqueValueImpl( field, entity.get().getId(), mvccEntity.getVersion() ); uniqueDeleteBatch.add(uniqueValueStrat.deleteCQL(scope, toDelete )); } } // execute the batch statements for deleting unique field entries session.execute(uniqueDeleteBatch); logEntryStrat.delete( scope, entity.get().getId(), mvccEntity.getVersion() ); } } }
log.debug("Entity Wrapper Deserialized: " + StringSerializer.get().fromByteBuffer(byteBuffer)); throw new DataCorruptionException("Unable to read entity data", e);
throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e );
throw new EntityTooLargeException(Entity.fromMap(wrapper.getEntityMap()), maxEntrySize, wrapperBytes.length, "Your entity cannot exceed " + maxEntrySize + " bytes. The entity you tried to save was " + wrapperBytes.length + " bytes");
private void confirmUniqueFields( MvccEntity mvccEntity, UUID version, ApplicationScope scope, MutationBatch logMutation) { final Entity entity = mvccEntity.getEntity().get(); // re-write the unique values but this time with no TTL final BatchStatement uniqueBatch = new BatchStatement(); for ( Field field : EntityUtils.getUniqueFields(mvccEntity.getEntity().get()) ) { UniqueValue written = new UniqueValueImpl( field, entity.getId(), version); uniqueBatch.add(uniqueValueStrat.writeCQL(scope, written, -1 )); logger.debug("Finalizing {} unique value {}", field.getName(), field.getValue().toString()); } try { logMutation.execute(); session.execute(uniqueBatch); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new WriteCommitException( mvccEntity, scope, "Failed to execute write asynchronously ", e ); } }
} catch (ConnectionException e) { logger.error("Failed to execute write ", e); throw new WriteStartException(nextStage, applicationScope, "Failed to execute write ", e); } catch (NullPointerException e) { logger.error("Failed to execute write ", e); throw new WriteStartException(nextStage, applicationScope, "Failed to execute write", e);
entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" );
@Test public void writeWithUniqueValues() { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); } { try { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); manager.write( newEntity, null ).toBlocking().last(); fail( "Write should have thrown an exception" ); } catch ( Exception ex ) { WriteUniqueVerifyException e = ( WriteUniqueVerifyException ) ex; assertEquals( 1, e.getViolations().size() ); } } }
throw new DataCorruptionException( "Unable to de-serialze entity", e ); throw new DataCorruptionException( "Unable to read entity data", e );
private void verifyUniqueFieldsAkka(CollectionIoEvent<MvccEntity> ioevent) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); final MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); final ApplicationScope applicationScope = ioevent.getEntityCollection(); String authoritativeRegion = ioevent.getAuthoritativeRegion(); if ( StringUtils.isEmpty(authoritativeRegion) ) { authoritativeRegion = uniqueValuesFig.getAuthoritativeRegion(); } if ( StringUtils.isEmpty(authoritativeRegion) ) { authoritativeRegion = actorSystemFig.getRegionLocal(); } try { akkaUvService.reserveUniqueValues( applicationScope, entity, mvccEntity.getVersion(), authoritativeRegion ); } catch (UniqueValueException e) { Map<String, Field> violations = new HashMap<>(); violations.put( e.getField().getName(), e.getField() ); throw new WriteUniqueVerifyException( mvccEntity, applicationScope, violations ); } }
if ( cre.isBootstrapping() ) {
throw new CollectionRuntimeException( null, collectionScope, "An error occurred connecting to cassandra", e );
throw new EntityTooLargeException( entity, maxEntrySize, entityBytes.length, "Your entity cannot exceed " + maxEntrySize + " bytes. The entity you tried to save was " + entityBytes.length + " bytes" );
throw new WriteCommitException( mvccEntity, applicationScope, "Failed to execute write asynchronously ", e );
assertTrue( !e.getViolations().isEmpty() );
throw new DataCorruptionException( "Unable to de-serialze entity", e ); throw new DataCorruptionException( "Unable to read entity data", e );