use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.
the class RealVoltDB method stageSchemaFiles.
private void stageSchemaFiles(Configuration config) {
if (config.m_userSchema == null) {
// nothing to do
return;
}
// this is validated during command line parsing and will be true unless disk faults
assert (config.m_userSchema.isFile());
File stagedCatalogFH = new VoltFile(getStagedCatalogPath(getVoltDBRootPath()));
if (!config.m_forceVoltdbCreate && stagedCatalogFH.exists()) {
VoltDB.crashLocalVoltDB("A previous database was initialized with a schema. You must init with --force to overwrite the schema.");
}
final boolean standalone = false;
final boolean isXCDR = false;
VoltCompiler compiler = new VoltCompiler(standalone, isXCDR);
compiler.setInitializeDDLWithFiltering(true);
if (!compiler.compileFromSchemaAndClasses(config.m_userSchema, config.m_stagedClassesPath, stagedCatalogFH)) {
VoltDB.crashLocalVoltDB("Could not compile specified schema " + config.m_userSchema);
}
}
use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.
the class RealVoltDB method stageDeploymentFileForInitialize.
/**
* Takes the deployment file given at initialization and the voltdb root given as
* a command line options, and it performs the following tasks:
* <p><ul>
* <li>creates if necessary the voltdbroot directory
* <li>fail if voltdbroot is already configured and populated with database artifacts
* <li>creates command log, DR, snapshot, and export directories
* <li>creates the config directory under voltdbroot
* <li>moves the deployment file under the config directory
* </ul>
* @param config
* @param dt a {@link DeploymentType}
*/
private void stageDeploymentFileForInitialize(Configuration config, DeploymentType dt) {
String deprootFN = dt.getPaths().getVoltdbroot().getPath();
File deprootFH = new VoltFile(deprootFN);
File cnfrootFH = config.m_voltdbRoot;
if (!cnfrootFH.exists() && !cnfrootFH.mkdirs()) {
VoltDB.crashLocalVoltDB("Unable to create the voltdbroot directory in " + cnfrootFH, false, null);
}
try {
File depcanoFH = null;
try {
depcanoFH = deprootFH.getCanonicalFile();
} catch (IOException e) {
depcanoFH = deprootFH;
}
File cnfcanoFH = cnfrootFH.getCanonicalFile();
if (!cnfcanoFH.equals(depcanoFH)) {
dt.getPaths().getVoltdbroot().setPath(cnfrootFH.getPath());
}
// root in deployment conflicts with command line voltdbroot
if (!VoltDB.DBROOT.equals(deprootFN)) {
consoleLog.info("Ignoring voltdbroot \"" + deprootFN + "\" specified in the deployment file");
hostLog.info("Ignoring voltdbroot \"" + deprootFN + "\" specified in the deployment file");
}
} catch (IOException e) {
VoltDB.crashLocalVoltDB("Unable to resolve voltdbroot location: " + config.m_voltdbRoot, false, e);
return;
}
// check for already existing artifacts
List<String> nonEmptyPaths = managedPathsWithFiles(config, dt);
if (!nonEmptyPaths.isEmpty()) {
StringBuilder crashMessage = new StringBuilder("Files from a previous database session exist in the managed directories:");
for (String nonEmptyPath : nonEmptyPaths) {
crashMessage.append("\n - " + nonEmptyPath);
}
crashMessage.append("\nUse the start command to start the initialized database or use init --force" + " to initialize a new database session overwriting existing files.");
VoltDB.crashLocalVoltDB(crashMessage.toString());
return;
}
// create the config subdirectory
File confDH = getConfigDirectory(config);
if (!confDH.exists() && !confDH.mkdirs()) {
VoltDB.crashLocalVoltDB("Unable to create the config directory " + confDH);
return;
}
// create the remaining paths
if (config.m_isEnterprise) {
List<String> failed = m_nodeSettings.ensureDirectoriesExist();
if (!failed.isEmpty()) {
String msg = "Unable to access or create the following directories:\n " + Joiner.on("\n ").join(failed);
VoltDB.crashLocalVoltDB(msg);
return;
}
}
//Now its safe to Save .paths
m_nodeSettings.store();
//Now that we are done with deployment configuration set all path null.
dt.setPaths(null);
// log message unconditionally indicating that the provided host-count and admin-mode settings in
// deployment, if any, will be ignored
consoleLog.info("When using the INIT command, some deployment file settings (hostcount and voltdbroot path) " + "are ignored");
hostLog.info("When using the INIT command, some deployment file settings (hostcount and voltdbroot path) are " + "ignored");
File depFH = getConfigLogDeployment(config);
try (FileWriter fw = new FileWriter(depFH)) {
fw.write(CatalogUtil.getDeployment(dt, true));
} catch (IOException | RuntimeException e) {
VoltDB.crashLocalVoltDB("Unable to marshal deployment configuration to " + depFH, false, e);
}
// Save cluster settings properties derived from the deployment file
ClusterSettings.create(CatalogUtil.asClusterSettingsMap(dt)).store();
}
use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.
the class OnDemandBinaryLogger method getStream.
private static Stuff getStream(final String name) throws IOException {
Stuff s = m_files.get(name);
if (s == null) {
File f = new VoltFile(path, name);
f.delete();
RandomAccessFile ras = new RandomAccessFile(f, "rw");
ras.seek(8);
SnappyOutputStream sos = new SnappyOutputStream(new FileOutputStream(ras.getFD()));
DataOutputStream dos = new DataOutputStream(sos);
s = new Stuff();
s.dos = dos;
s.count = ras.getChannel().map(MapMode.READ_WRITE, 0, 8);
s.count.order(ByteOrder.nativeOrder());
m_files.put(name, s);
}
return s;
}
use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.
the class SnapshotUtil method writeHashinatorConfig.
/**
* Write the hashinator config file for a snapshot
* @param instId instance ID
* @param path path to which snapshot files will be written
* @param nonce nonce used to distinguish this snapshot
* @param hostId host ID where this is happening
* @param hashData serialized hash configuration data
* @return Runnable object for asynchronous write flushing
* @throws IOException
*/
public static Runnable writeHashinatorConfig(InstanceId instId, String path, String nonce, int hostId, HashinatorSnapshotData hashData) throws IOException {
final File file = new VoltFile(path, constructHashinatorConfigFilenameForNonce(nonce, hostId));
if (file.exists()) {
if (!file.delete()) {
throw new IOException("Unable to replace existing hashinator config " + file);
}
}
boolean success = false;
try {
final FileOutputStream fos = new FileOutputStream(file);
ByteBuffer fileBuffer = hashData.saveToBuffer(instId);
fos.getChannel().write(fileBuffer);
success = true;
return new Runnable() {
@Override
public void run() {
try {
fos.getChannel().force(true);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
};
} finally {
if (!success) {
file.delete();
}
}
}
use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.
the class SnapshotUtil method retrieveDigests.
public static List<JSONObject> retrieveDigests(String path, String nonce, VoltLogger logger) throws Exception {
VoltFile directoryWithDigest = new VoltFile(path);
ArrayList<JSONObject> digests = new ArrayList<JSONObject>();
if (directoryWithDigest.listFiles() == null) {
return digests;
}
for (File f : directoryWithDigest.listFiles()) {
if (//old style digest name
f.getName().equals(nonce + ".digest") || (f.getName().startsWith(nonce + "-host_") && f.getName().endsWith(".digest"))) {
//new style
JSONObject retval = CRCCheck(f, logger);
if (retval != null) {
digests.add(retval);
}
}
}
return digests;
}
Aggregations