use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.
the class SplittingPaxosStateLog method createWithMigration.
public static <V extends Persistable & Versionable> PaxosStateLog<V> createWithMigration(PaxosStorageParameters params, Persistable.Hydrator<V> hydrator, LegacyOperationMarkers legacyOperationMarkers, OptionalLong migrateFrom) {
String logDirectory = params.fileBasedLogDirectory().orElseThrow(() -> new SafeIllegalStateException("We currently need to have file-based storage"));
NamespaceAndUseCase namespaceUseCase = params.namespaceAndUseCase();
PaxosStateLogMigrator.MigrationContext<V> migrationContext = ImmutableMigrationContext.<V>builder().sourceLog(PaxosStateLogImpl.createFileBacked(logDirectory)).destinationLog(SqlitePaxosStateLog.create(namespaceUseCase, params.sqliteDataSource())).hydrator(hydrator).migrationState(SqlitePaxosStateLogMigrationState.create(namespaceUseCase, params.sqliteDataSource())).migrateFrom(migrateFrom).namespaceAndUseCase(namespaceUseCase).skipValidationAndTruncateSourceIfMigrated(params.skipConsistencyCheckAndTruncateOldPaxosLog()).build();
long cutoff = PaxosStateLogMigrator.migrateAndReturnCutoff(migrationContext);
if (params.skipConsistencyCheckAndTruncateOldPaxosLog()) {
return migrationContext.destinationLog();
}
SplittingParameters<V> splittingParameters = ImmutableSplittingParameters.<V>builder().legacyLog(migrationContext.sourceLog()).currentLog(migrationContext.destinationLog()).cutoffInclusive(cutoff).legacyOperationMarkers(legacyOperationMarkers).build();
return SplittingPaxosStateLog.create(splittingParameters);
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.
the class AtlasDbServicesConnector method connect.
public AtlasDbServices connect() {
if (services != null) {
throw new SafeIllegalStateException("connect() has already been called");
}
DockerizedDatabaseUri dburi = DockerizedDatabaseUri.fromUriString(uri);
KeyValueServiceConfig config = dburi.getKeyValueServiceInstrumentation().getKeyValueServiceConfig(dburi.getAddress());
Optional<KeyValueServiceRuntimeConfig> runtimeConfig = dburi.getKeyValueServiceInstrumentation().getKeyValueServiceRuntimeConfig(dburi.getAddress());
ImmutableAtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder().keyValueService(config).build();
ImmutableAtlasDbRuntimeConfig atlasDbRuntimeConfig = ImmutableAtlasDbRuntimeConfig.defaultRuntimeConfig().withKeyValueService(runtimeConfig);
ServicesConfigModule servicesConfigModule = ServicesConfigModule.create(atlasDbConfig, atlasDbRuntimeConfig);
services = DaggerAtlasDbServices.builder().servicesConfigModule(servicesConfigModule).build();
return services;
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.
the class TimeLockAgent method verifyTimestampBoundPersisterConfiguration.
@VisibleForTesting
static void verifyTimestampBoundPersisterConfiguration(HikariDataSource sqliteDataSource, TsBoundPersisterConfiguration currentUserConfiguration, boolean reseedPersistedPersisterConfiguration, ObjectMapper objectMapper) {
PersistenceConfigStore store = new PersistenceConfigStore(objectMapper, SqliteBlobStore.create(sqliteDataSource));
if (reseedPersistedPersisterConfiguration) {
log.info("As configured, updating the configuration persisted in the SQLite database.", SafeArg.of("ourConfiguration", currentUserConfiguration));
store.storeConfig(currentUserConfiguration);
return;
}
Optional<TsBoundPersisterConfiguration> configInDatabase = store.getPersistedConfig();
if (!configInDatabase.isPresent()) {
log.info("There is no config in the SQLite database indicating where timestamps are being stored. We are" + " thus assuming that your current configuration is indeed correct, and using that as a" + " future reference.", SafeArg.of("configuration", currentUserConfiguration));
store.storeConfig(currentUserConfiguration);
return;
}
TsBoundPersisterConfiguration presentConfig = configInDatabase.get();
if (currentUserConfiguration.isLocationallyIncompatible(presentConfig)) {
log.error("Configuration in the SQLite database does not agree with what the user has provided!", SafeArg.of("ourConfiguration", currentUserConfiguration), SafeArg.of("persistedConfiguration", presentConfig));
throw new SafeIllegalStateException("Configuration in the SQLite database does not agree with the" + " configuration the user has provided, in a way that is known to be incompatible. For integrity" + " of the service, we will shut down and cannot serve any user requests. If you have" + " accidentally changed the DB configs, please revert them. If this is intentional, you can" + " update the config stored in the database by setting the relevant override flag.");
} else {
log.info("Passed consistency check: the config in the SQLite database agrees with our config.");
}
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project conjure by palantir.
the class ConjureParserUtils method innerParseImportObjects.
private static Map<TypeName, TypeDefinition> innerParseImportObjects(Map<Namespace, ConjureImports> conjureImports, Map<String, AnnotatedConjureSourceFile> externalTypes, Set<String> loadedFiles) {
Map<TypeName, TypeDefinition> allDefinitions = new HashMap<>();
conjureImports.values().forEach(conjureImport -> {
String pathKey = conjureImport.absoluteFile().orElseThrow(() -> new SafeIllegalStateException("Absolute file MUST be resolved as part of parsing stage")).getAbsolutePath();
// These structures are potentially recursive; load in any given conjure file once
if (loadedFiles.contains(pathKey)) {
return;
}
loadedFiles.add(pathKey);
AnnotatedConjureSourceFile annotatedConjureSourceFile = externalTypes.get(pathKey);
Preconditions.checkNotNull(annotatedConjureSourceFile, "Couldn't find import", UnsafeArg.of("file", conjureImport.file()));
ConjureSourceFile conjureDef = annotatedConjureSourceFile.conjureSourceFile();
Map<Namespace, String> importProviders = annotatedConjureSourceFile.importProviders();
ReferenceTypeResolver importTypeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(conjureDef.types(), importProviders, externalTypes);
allDefinitions.putAll(parseObjects(conjureDef.types(), importTypeResolver));
allDefinitions.putAll(innerParseImportObjects(conjureDef.types().conjureImports(), externalTypes, loadedFiles));
});
return allDefinitions;
}
use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project conjure-java-runtime by palantir.
the class AsyncSerializableErrorCallAdapterFactory method get.
@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] _annotations, Retrofit _retrofit) {
Type outerType = getRawType(returnType);
if (outerType != CompletableFuture.class && outerType != ListenableFuture.class) {
return null;
}
if (!(returnType instanceof ParameterizedType)) {
throw new SafeIllegalStateException("CompletableFuture/ListenableFuture return type must be parameterized" + " as <Foo> or <? extends Foo>");
}
Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType);
if (getRawType(innerType) != Response.class) {
// Generic type is not Response<T>. Use it for body-only adapter.
return getCallAdapter(outerType, innerType);
}
return null;
}
Aggregations