use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBBackup method takeBackupNoLock.
/**
* Takes a hot backup when another process has locked the BDB database.
*
* @param fromdir The source directory path.
* @param todir The destination directory path.
*
* @return A list of all of the names of the files succesfully backed up.
*/
public String[] takeBackupNoLock(String fromdir, String todir) {
if (log.isDebugEnabled()) {
log.debug("public void takeBackupNoLock(String fromdir = " + fromdir + ", String todir = " + todir + "): called");
}
File fromDirFile = new File(fromdir);
if (!fromDirFile.isDirectory()) {
throw new IllegalArgumentException("The specified fromdir(" + fromdir + ") must be the directory containing your bdbstore.");
}
File toDirFile = new File(todir);
if (!toDirFile.exists()) {
// Create directory if it doesn't exist
toDirFile.mkdirs();
if (log.isDebugEnabled()) {
log.debug("Created backup directory:" + toDirFile);
}
}
if (!toDirFile.isDirectory()) {
throw new IllegalArgumentException("The specified todir(" + todir + ") must be a directory.");
}
// Repeat until manage to open consistent set of files for reading.
boolean consistentSet = false;
FileInputStream[] fileInputStreams = new FileInputStream[0];
File[] fileSet = new File[0];
long start = System.currentTimeMillis();
while (!consistentSet) {
// List all .jdb files in the directory.
fileSet = fromDirFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(LOG_FILE_SUFFIX);
}
});
if (fileSet == null || fileSet.length == 0) {
throw new StoreException("There are no BDB log files to backup in the '" + fromdir + "' directory.");
}
// The files must be copied in alphabetical order (numerical in effect)
Arrays.sort(fileSet);
// Open them all for reading.
fileInputStreams = new FileInputStream[fileSet.length];
for (int i = 0; i < fileSet.length; i++) {
try {
fileInputStreams[i] = new FileInputStream(fileSet[i]);
} catch (FileNotFoundException e) {
// Close any files opened for reading so far.
for (int j = 0; j < i; j++) {
if (fileInputStreams[j] != null) {
try {
fileInputStreams[j].close();
} catch (IOException ioEx) {
// Rethrow this as a runtime exception, as something strange has happened.
throw new StoreException(ioEx);
}
}
}
// Could not open a consistent file set so try again.
break;
}
// A consistent set has been opened if all files were successfully opened for reading.
if (i == (fileSet.length - 1)) {
consistentSet = true;
}
}
// Check that the script has not timed out, and raise an error if it has.
long now = System.currentTimeMillis();
if ((now - start) > TIMEOUT) {
throw new StoreException("Hot backup script failed to complete in " + (TIMEOUT / 1000) + " seconds.");
}
}
// Copy the consistent set of open files.
List<String> backedUpFileNames = new LinkedList<String>();
for (int j = 0; j < fileSet.length; j++) {
File destFile = new File(todir + File.separator + fileSet[j].getName());
try {
Files.copy(fileInputStreams[j], destFile.toPath());
} catch (IOException ioe) {
throw new StoreException(ioe.getMessage() + " fromDir:" + fromdir + " toDir:" + toDirFile, ioe);
}
backedUpFileNames.add(destFile.getName());
// Close all of the files.
try {
fileInputStreams[j].close();
} catch (IOException e) {
// Rethrow this as a runtime exception, as something strange has happened.
throw new StoreException(e);
}
}
return backedUpFileNames.toArray(new String[backedUpFileNames.size()]);
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBConfigurationStore method writeHierarchyRecords.
private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject) {
OperationStatus status;
HierarchyKeyBinding hierarchyBinding = HierarchyKeyBinding.getInstance();
DatabaseEntry hierarchyKey = new DatabaseEntry();
DatabaseEntry hierarchyValue = new DatabaseEntry();
for (Map.Entry<String, UUID> parent : configuredObject.getParents().entrySet()) {
hierarchyBinding.objectToEntry(new HierarchyKey(configuredObject.getId(), parent.getKey()), hierarchyKey);
UUIDTupleBinding.getInstance().objectToEntry(parent.getValue(), hierarchyValue);
status = getConfiguredObjectHierarchyDb().put(txn, hierarchyKey, hierarchyValue);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " parent record to database: " + status);
}
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBConfigurationStore method storeConfiguredObjectEntry.
private void storeConfiguredObjectEntry(final Transaction txn, ConfiguredObjectRecord configuredObject) throws StoreException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Storing configured object record: " + configuredObject);
}
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
uuidBinding.objectToEntry(configuredObject.getId(), key);
DatabaseEntry value = new DatabaseEntry();
ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
queueBinding.objectToEntry(configuredObject, value);
try {
OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
}
writeHierarchyRecords(txn, configuredObject);
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject + " to database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBPreferenceStore method doClose.
@Override
protected void doClose() {
try {
_environmentFacade.close();
_environmentFacade = null;
} catch (RuntimeException e) {
throw new StoreException("Exception occurred on preference store close", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class ConfiguredObjectBinding method objectToEntry.
@Override
public void objectToEntry(ConfiguredObjectRecord object, TupleOutput tupleOutput) {
try {
StringWriter writer = new StringWriter();
final ObjectMapper objectMapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
objectMapper.writeValue(writer, object.getAttributes());
tupleOutput.writeString(object.getType());
tupleOutput.writeString(writer.toString());
} catch (IOException e) {
throw new StoreException(e);
}
}
Aggregations