use of org.infinispan.persistence.keymappers.Key2StringMapper in project infinispan by infinispan.
the class JdbcStringBasedStore method createTableOperations.
@Override
protected TableOperations<K, V> createTableOperations(InitializationContext ctx, JdbcStringBasedStoreConfiguration configuration) {
this.configuration = ctx.getConfiguration();
this.marshalledEntryFactory = ctx.getMarshallableEntryFactory();
this.marshaller = ctx.getPersistenceMarshaller();
this.timeService = ctx.getTimeService();
this.keyPartitioner = configuration.segmented() ? ctx.getKeyPartitioner() : null;
int numSegments = ctx.getCache().getCacheConfiguration().clustering().hash().numSegments();
if (configuration.shared()) {
this.sizeSegments = IntSets.immutableRangeSet(numSegments);
} else {
this.sizeSegments = IntSets.concurrentSet(numSegments);
this.sizeSegments.addAll(IntSets.immutableRangeSet(numSegments));
}
String cacheName = ctx.getCache().getName();
TableManager<K, V> tableManager = TableManagerFactory.getManager(ctx, connectionFactory, configuration, ctx.getCache().getName());
tableManager.start();
if (!configuration.table().createOnStart()) {
Connection connection = null;
try {
connection = connectionFactory.getConnection();
// If meta exists, then ensure that the stored configuration is compatible with the current settings
if (tableManager.metaTableExists(connection)) {
TableManager.Metadata meta = tableManager.getMetadata(connection);
int storedSegments = meta.getSegments();
if (!configuration.segmented()) {
// ISPN-13135 number of segments was previously written incorrectly, so don't validate number for older versions
String versionStr = Version.decodeVersion(meta.getVersion());
List<Integer> versionParts = Arrays.stream(versionStr.split("\\.")).map(Integer::parseInt).collect(Collectors.toList());
// Ignore check if version < 12.1.5. Meta table only created since 12.0.0
if ((versionParts.get(0) > 12 || versionParts.get(2) > 4) && storedSegments != -1)
throw log.existingStoreNoSegmentation();
}
int configuredSegments = numSegments;
if (configuration.segmented() && storedSegments != configuredSegments)
throw log.existingStoreSegmentMismatch(storedSegments, configuredSegments);
tableManager.updateMetaTable(connection);
} else {
// The meta table does not exist, therefore we must be reading from a 11.x store. Migrate the old data
org.infinispan.util.logging.Log.PERSISTENCE.startMigratingPersistenceData(cacheName);
try {
migrateFromV11(ctx, tableManager);
} catch (SQLException e) {
throw org.infinispan.util.logging.Log.PERSISTENCE.persistedDataMigrationFailed(cacheName, e);
}
tableManager.createMetaTable(connection);
org.infinispan.util.logging.Log.PERSISTENCE.persistedDataSuccessfulMigrated(cacheName);
}
} finally {
connectionFactory.releaseConnection(connection);
}
}
try {
Object mapper = Util.loadClassStrict(configuration.key2StringMapper(), ctx.getGlobalConfiguration().classLoader()).newInstance();
if (mapper instanceof Key2StringMapper)
key2StringMapper = (Key2StringMapper) mapper;
} catch (Exception e) {
log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(), e.getClass().getName());
throw new IllegalStateException("This should not happen.", e);
}
if (log.isTraceEnabled()) {
log.tracef("Using key2StringMapper: %s", key2StringMapper.getClass().getName());
}
if (configuration.preload()) {
enforceTwoWayMapper("preload");
}
if (ctx.getCache().getCacheConfiguration() != null && ctx.getCache().getCacheConfiguration().clustering().cacheMode().isDistributed()) {
enforceTwoWayMapper("distribution/rehashing");
}
return tableManager;
}
use of org.infinispan.persistence.keymappers.Key2StringMapper in project infinispan by infinispan.
the class AbstractTableManager method start.
@Override
public void start() throws PersistenceException {
if (config.createOnStart()) {
Connection conn = null;
try {
conn = connectionFactory.getConnection();
if (!tableExists(conn, metaTableName)) {
createMetaTable(conn);
}
if (!tableExists(conn, dataTableName)) {
createDataTable(conn);
}
createIndex(conn, timestampIndexExt, config.timestampColumnName());
if (!dbMetadata.isSegmentedDisabled()) {
createIndex(conn, segmentIndexExt, config.segmentColumnName());
}
} finally {
connectionFactory.releaseConnection(conn);
}
}
JdbcStringBasedStoreConfiguration configuration = ctx.getConfiguration();
try {
Object mapper = Util.loadClassStrict(configuration.key2StringMapper(), ctx.getGlobalConfiguration().classLoader()).newInstance();
if (mapper instanceof Key2StringMapper)
key2StringMapper = (Key2StringMapper) mapper;
} catch (Exception e) {
log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(), e.getClass().getName());
throw new IllegalStateException("This should not happen.", e);
}
}
Aggregations