use of org.apache.derby.iapi.services.monitor.PersistentService in project derby by apache.
the class BaseMonitor method setLocale.
/**
* Set the locale for the service *outside* of boot time.
*
* @exception StandardException Standard Derby error.
*/
public Locale setLocale(Object serviceModule, String userDefinedLocale) throws StandardException {
TopService ts = findTopService(serviceModule);
if (ts == null)
return null;
PersistentService provider = ts.getServiceType();
if (provider == null)
return null;
String serviceName = ts.getKey().getIdentifier();
Properties properties = provider.getServiceProperties(serviceName, (Properties) null);
properties = new UpdateServiceProperties(provider, serviceName, properties, true);
return setLocale(properties, userDefinedLocale);
}
use of org.apache.derby.iapi.services.monitor.PersistentService in project derby by apache.
the class BaseMonitor method findProviderAndStartService.
/**
* Find a provider and start a service.
*/
private boolean findProviderAndStartService(String name, Properties properties, boolean bootTime) throws StandardException {
PersistentService actualProvider = null;
Properties serviceProperties = null;
String serviceName = null;
// see if the name already includes a service type
int colon = name.indexOf(':');
if (colon != -1) {
actualProvider = findProviderFromName(name, colon);
// throw an exception
if (actualProvider != null) {
serviceName = actualProvider.getCanonicalServiceName(name);
if (serviceName == null)
// we understand the type, but the service does not exist
return true;
serviceProperties = actualProvider.getServiceProperties(serviceName, properties);
if (serviceProperties == null)
// we understand the type, but the service does not exist
return true;
// see if this service does not want to be auto-booted.
if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue())
return true;
startProviderService(actualProvider, serviceName, serviceProperties);
// we understand the type
return true;
}
}
StandardException savedMse = null;
for (Enumeration e = new ProviderEnumeration(properties); e.hasMoreElements(); ) {
PersistentService provider = (PersistentService) e.nextElement();
String sn = provider.getCanonicalServiceName(name);
if (sn == null)
continue;
Properties p = null;
try {
p = provider.getServiceProperties(sn, properties);
// service does not exist.
if (p == null)
continue;
} catch (StandardException mse) {
savedMse = mse;
}
// yes we can attempt to boot this service
if (actualProvider == null) {
actualProvider = provider;
serviceName = sn;
serviceProperties = p;
continue;
}
// we have an ambigious service name
throw StandardException.newException(SQLState.AMBIGIOUS_PROTOCOL, name);
}
// the monitor claims to always understand these.
if (actualProvider == null)
return colon == -1;
if (savedMse != null)
throw savedMse;
// see if this service does not want to be auto-booted.
if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue())
return true;
startProviderService(actualProvider, serviceName, serviceProperties);
return true;
}
use of org.apache.derby.iapi.services.monitor.PersistentService in project derby by apache.
the class RawStore method backup.
/*
* Backup the database.
* Online backup copies all the database files (log, seg0 ...Etc) to the
* specified backup location without blocking any user operation for the
* duration of the backup. Stable copy is made of each page using
* page level latches and in some cases with the help of monitors.
* Transaction log is also backed up, this is used to bring the database to
* the consistent state on restore.
*
* <P> MT- only one thread is allowed to perform backup at any given time.
* Synchronized on this. Parallel backups are not supported.
*/
public synchronized void backup(Transaction t, File backupDir) throws StandardException {
if (!privExists(backupDir)) {
// if backup dir does not exist, go ahead and create it.
createBackupDirectory(backupDir);
} else {
if (!privIsDirectory(backupDir)) {
throw StandardException.newException(SQLState.RAWSTORE_CANNOT_BACKUP_TO_NONDIRECTORY, (File) backupDir);
}
if (privExists(new File(backupDir, PersistentService.PROPERTIES_NAME))) {
throw StandardException.newException(SQLState.RAWSTORE_CANNOT_BACKUP_INTO_DATABASE_DIRECTORY, (File) backupDir);
}
}
boolean error = true;
boolean renamed = false;
boolean renameFailed = false;
File oldbackup = null;
File backupcopy = null;
OutputStreamWriter historyFile = null;
StorageFile dbHistoryFile = null;
File backupHistoryFile = null;
LogInstant backupInstant = logFactory.getFirstUnflushedInstant();
try {
// get name of the current db, ie. database directory of current db.
StorageFile dbase = storageFactory.newStorageFile(null);
String canonicalDbName = storageFactory.getCanonicalName();
String dbname = StringUtil.shortDBName(canonicalDbName, storageFactory.getSeparator());
// append to end of history file
historyFile = privFileWriter(storageFactory.newStorageFile(BACKUP_HISTORY), true);
backupcopy = new File(backupDir, dbname);
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_STARTED, canonicalDbName, getFilePath(backupcopy)));
// check if a backup copy of this database already exists,
if (privExists(backupcopy)) {
// first make a backup of the backup
oldbackup = new File(backupDir, dbname + ".OLD");
if (privExists(oldbackup)) {
if (privIsDirectory(oldbackup))
privRemoveDirectory(oldbackup);
else
privDelete(oldbackup);
}
if (!privRenameTo(backupcopy, oldbackup)) {
renameFailed = true;
throw StandardException.newException(SQLState.RAWSTORE_ERROR_RENAMING_FILE, backupcopy, oldbackup);
} else {
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_MOVED_BACKUP, getFilePath(backupcopy), getFilePath(oldbackup)));
renamed = true;
}
}
// create the backup database directory
createBackupDirectory(backupcopy);
dbHistoryFile = storageFactory.newStorageFile(BACKUP_HISTORY);
backupHistoryFile = new File(backupcopy, BACKUP_HISTORY);
// copy the history file into the backup.
if (!privCopyFile(dbHistoryFile, backupHistoryFile))
throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, dbHistoryFile, backupHistoryFile);
// if they are any jar file stored in the database, copy them into
// the backup.
StorageFile jarDir = storageFactory.newStorageFile(FileResource.JAR_DIRECTORY_NAME);
if (privExists(jarDir)) {
// find the list of schema directories under the jar dir and
// then copy only the plain files under those directories. One
// could just use the recursive copy of directory to copy all
// the files under the jar dir, but the problem with that is if
// a user gives jar directory as the backup path by mistake,
// copy will fail while copying the backup dir onto itself in
// recursion
String[] jarDirContents = privList(jarDir);
File backupJarDir = new File(backupcopy, FileResource.JAR_DIRECTORY_NAME);
// Create the backup jar directory
createBackupDirectory(backupJarDir);
LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
// DERBY-5357 UUIDs introduced in jar file names in 10.9
boolean uuidSupported = lcc.getDataDictionary().checkVersion(DataDictionary.DD_VERSION_DERBY_10_9, null);
if (uuidSupported) {
// no subdirectories
for (int i = 0; i < jarDirContents.length; i++) {
StorageFile jar = storageFactory.newStorageFile(jarDir, jarDirContents[i]);
File backupJar = new File(backupJarDir, jarDirContents[i]);
if (privIsDirectory(new File(jar.getPath()))) {
// We no longer expect directories inside
continue;
// 'jar'. Need check to make the weird
// test #2 in BackupPathTests.java work:
// it does a backup of the db into its
// own(!) jar file directory, so trying
// to copy that db file into itself two
// levels down would fail.
}
if (!privCopyFile(jar, backupJar)) {
throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, jar, backupJar);
}
}
} else {
for (int i = 0; i < jarDirContents.length; i++) {
StorageFile jarSchemaDir = storageFactory.newStorageFile(jarDir, jarDirContents[i]);
File backupJarSchemaDir = new File(backupJarDir, jarDirContents[i]);
if (!privCopyDirectory(jarSchemaDir, backupJarSchemaDir, (byte[]) null, null, false)) {
throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, jarSchemaDir, backupJarSchemaDir);
}
}
}
}
// save service properties into the backup, Read in property
// from service.properties file, remove logDevice from it,
// then write it to the backup.
StorageFile logdir = logFactory.getLogDirectory();
try {
String name = getServiceName(this);
PersistentService ps = getMonitor().getServiceType(this);
String fullName = ps.getCanonicalServiceName(name);
Properties prop = ps.getServiceProperties(fullName, (Properties) null);
StorageFile defaultLogDir = storageFactory.newStorageFile(LogFactory.LOG_DIRECTORY_NAME);
if (!logdir.equals(defaultLogDir)) {
prop.remove(Attribute.LOG_DEVICE);
if (SanityManager.DEBUG) {
SanityManager.ASSERT(prop.getProperty(Attribute.LOG_DEVICE) == null, "cannot get rid of logDevice property");
}
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_EDITED_SERVICEPROPS));
}
// save the service properties into the backup.
ps.saveServiceProperties(backupcopy.getPath(), prop);
} catch (StandardException se) {
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_ERROR_EDIT_SERVICEPROPS) + se);
// skip the rest and let finally block clean up
return;
}
// Incase of encrypted database and the key is an external
// encryption key, there is an extra file with name
// Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE, this file should be
// copied in to the backup.
StorageFile verifyKeyFile = storageFactory.newStorageFile(Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
if (privExists(verifyKeyFile)) {
File backupVerifyKeyFile = new File(backupcopy, Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
if (!privCopyFile(verifyKeyFile, backupVerifyKeyFile))
throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, verifyKeyFile, backupVerifyKeyFile);
}
File logBackup = new File(backupcopy, LogFactory.LOG_DIRECTORY_NAME);
// this is wierd, delete it
if (privExists(logBackup)) {
privRemoveDirectory(logBackup);
}
// Create the log directory
createBackupDirectory(logBackup);
// do a checkpoint to get the persistent store up to date.
logFactory.checkpoint(this, dataFactory, xactFactory, true);
// start the transaction log backup.
logFactory.startLogBackup(logBackup);
File segBackup = new File(backupcopy, "seg0");
// Create the data segment directory
createBackupDirectory(segBackup);
// backup all the information in the data segment.
dataFactory.backupDataFiles(t, segBackup);
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_DATA_SEG_BACKUP_COMPLETED, getFilePath(segBackup)));
// copy the log that got generated after the backup started to
// backup location and tell the logfactory that backup has come
// to end.
logFactory.endLogBackup(logBackup);
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_COPIED_LOG, getFilePath(logdir), getFilePath(logBackup)));
error = false;
} catch (IOException ioe) {
throw StandardException.newException(SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe);
} finally {
try {
if (error) {
// Abort all activity related to backup in the log factory.
logFactory.abortLogBackup();
// not an half backed one.
if (!renameFailed)
privRemoveDirectory(backupcopy);
if (renamed)
// recover the old backup
privRenameTo(oldbackup, backupcopy);
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_ABORTED));
} else {
// success, remove the old backup copy
if (renamed && privExists(oldbackup)) {
// get rid of the old backup
privRemoveDirectory(oldbackup);
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_REMOVED_BACKUP, getFilePath(oldbackup)));
}
logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_COMPLETED, backupInstant));
// backup information into the backup.
if (!privCopyFile(dbHistoryFile, backupHistoryFile))
throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, dbHistoryFile, backupHistoryFile);
}
historyFile.close();
} catch (IOException ioe) {
try {
historyFile.close();
} catch (IOException ioe2) {
}
;
throw StandardException.newException(SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe);
}
}
}
use of org.apache.derby.iapi.services.monitor.PersistentService in project derby by apache.
the class LogToFile method getLogStorageFactory.
// end of boot
private void getLogStorageFactory() throws StandardException {
if (logDevice == null) {
DataFactory df = (DataFactory) findServiceModule(this, DataFactory.MODULE);
logStorageFactory = (WritableStorageFactory) df.getStorageFactory();
} else {
try {
PersistentService ps = getMonitor().getServiceType(this);
logStorageFactory = (WritableStorageFactory) ps.getStorageFactoryInstance(false, logDevice, null, null);
} catch (IOException ioe) {
if (SanityManager.DEBUG)
SanityManager.NOTREACHED();
throw StandardException.newException(SQLState.LOG_FILE_NOT_FOUND, ioe, logDevice);
}
}
}
use of org.apache.derby.iapi.services.monitor.PersistentService in project derby by apache.
the class RAMAccessManager method createReadMeFiles.
/**
* DERBY-5996(Create readme files (cautioning users against modifying
* database files) at database hard upgrade time)
* This gets called during hard upgrade. It will create 3 readme files
* one in database directory, one in "seg0" directory and one in log
* directory. These readme files warn users against touching any of
* files associated with derby database
*/
public void createReadMeFiles() throws StandardException {
// creating readme in "seg0" directory
rawstore.createDataWarningFile();
// creating readme in log directory
LogFactory logFactory = (LogFactory) findServiceModule(this, rawstore.getLogFactoryModule());
logFactory.createDataWarningFile();
// creating readme in root database directory
DataFactory dataFactory = (DataFactory) findServiceModule(this, rawstore.getDataFactoryModule());
PersistentService ps = getMonitor().getServiceType(rawstore);
ps.createDataWarningFile(dataFactory.getStorageFactory());
}
Aggregations