use of org.apache.tephra.persist.TransactionSnapshot in project cdap by caskdata.
the class TransactionManagerDebuggerMain method takeSnapshot.
/**
* Take a snapshot from the CDAP transaction manager and retrieve it.
* @return the transaction manager snapshot just taken
*/
private TransactionSnapshot takeSnapshot() {
URL url;
HttpURLConnection connection = null;
try {
url = new URL("http://" + hostname + ":" + portNumber + "/v3/transactions/state");
connection = (HttpURLConnection) url.openConnection();
if (accessToken != null) {
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
}
System.out.println("About to take a snapshot of the transaction manager at " + url.toURI() + ", timestamp is " + System.currentTimeMillis() + " ms");
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
// Retrieve and deserialize the snapshot
TransactionSnapshot snapshot;
try (InputStream input = connection.getInputStream()) {
snapshot = codecProvider.decode(input);
}
System.out.println("Snapshot taken and retrieved properly, snapshot timestamp is " + snapshot.getTimestamp() + " ms");
if (persistingFilename != null) {
// Persist the snapshot on disk for future queries and debugging
File outputFile = new File(persistingFilename);
try (OutputStream out = new FileOutputStream(outputFile)) {
// todo use pipes here to avoid having everyhting in memory twice
codecProvider.encode(out, snapshot);
}
System.out.println("Snapshot persisted on your disk as " + outputFile.getAbsolutePath() + " for future queries.");
} else {
System.out.println("Persist option not activated - Snapshot won't be persisted on your disk.");
}
return snapshot;
} else if (responseCode == 401) {
readUnauthorizedError(connection);
} else {
System.out.println("Snapshot could not be taken. Error code: " + responseCode);
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
use of org.apache.tephra.persist.TransactionSnapshot in project cdap by caskdata.
the class TransactionManagerDebuggerMain method retrieveSnapshot.
/**
* Retrieve a persisted snapshot taken in the past.
* @return the decoded transaction manager snapshot
*/
private TransactionSnapshot retrieveSnapshot() {
try {
System.out.println("Retrieving snapshot from file " + existingFilename);
File snapshotFile = new File(existingFilename);
try (FileInputStream fis = new FileInputStream(snapshotFile)) {
TransactionSnapshot snapshot = codecProvider.decode(fis);
System.out.println("Snapshot retrieved, timestamp is " + snapshot.getTimestamp() + " ms.");
return snapshot;
}
} catch (IOException e) {
System.out.println("File " + existingFilename + " could not be read.");
e.printStackTrace();
return null;
}
}
use of org.apache.tephra.persist.TransactionSnapshot in project cdap by caskdata.
the class HBaseTableCoprocessorTestRun method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() throws Exception {
hConf = HBASE_TEST_BASE.getConfiguration();
hConf.set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
cConf.set(Constants.CFG_HDFS_NAMESPACE, cConf.get(Constants.CFG_LOCAL_DATA_DIR));
cConf.set(Constants.CFG_HDFS_USER, System.getProperty("user.name"));
// Reduce the metadata cache refresh frequency for unit tests
cConf.set(Constants.MessagingSystem.COPROCESSOR_METADATA_CACHE_UPDATE_FREQUENCY_SECONDS, Integer.toString(METADATA_CACHE_EXPIRY));
hBaseAdmin = HBASE_TEST_BASE.getHBaseAdmin();
hBaseAdmin.getConfiguration().set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
tableUtil = new HBaseTableUtilFactory(cConf).get();
ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get();
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class);
tableFactory = new HBaseTableFactory(cConf, hBaseAdmin.getConfiguration(), tableUtil, locationFactory);
new ConfigurationWriter(hConf, cConf).write(ConfigurationReader.Type.DEFAULT, cConf);
// write an initial transaction snapshot
invalidList.addAll(ImmutableList.of(V[3], V[5], V[7]));
TransactionSnapshot txSnapshot = TransactionSnapshot.copyFrom(System.currentTimeMillis(), V[6] - 1, V[7], invalidList, // this will set visibility upper bound to V[6]
Maps.newTreeMap(ImmutableSortedMap.of(V[6], new TransactionManager.InProgressTx(V[6] - 1, Long.MAX_VALUE, TransactionManager.InProgressType.SHORT))), new HashMap<Long, TransactionManager.ChangeSet>(), new TreeMap<Long, TransactionManager.ChangeSet>());
HDFSTransactionStateStorage tmpStorage = new HDFSTransactionStateStorage(hConf, new SnapshotCodecProvider(hConf), new TxMetricsCollector());
tmpStorage.startAndWait();
tmpStorage.writeSnapshot(txSnapshot);
tmpStorage.stopAndWait();
}
Aggregations