use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class JDBCImple_driver method reveal_state.
public boolean reveal_state(Uid objUid, String typeName) throws ObjectStoreException {
// Taken this requirement from ObjStoreBrowser
if (typeName.startsWith("/"))
typeName = typeName.substring(1);
boolean result = false;
Connection connection = null;
PreparedStatement pstmt = null;
try {
connection = jdbcAccess.getConnection();
pstmt = connection.prepareStatement("UPDATE " + tableName + " SET Hidden = 0 WHERE TypeName = ? AND UidString = ?");
pstmt.setString(1, typeName);
pstmt.setString(2, objUid.stringForm());
int rowcount = pstmt.executeUpdate();
connection.commit();
if (rowcount > 0) {
result = true;
}
} catch (Exception e) {
tsLogger.i18NLogger.warn_objectstore_JDBCImple_2(e);
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// Ignore
}
}
}
return result;
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class FileSystemStore method allTypesInternal.
private boolean allTypesInternal(OutputObjectState foundTypes, String root) throws ObjectStoreException {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("FileSystemStore.allTypes(" + foundTypes + ", " + root + ")");
}
boolean result = true;
String directory = new String(fullStoreName + File.separator + root);
File f = new File(directory);
String[] entry = f.list();
if ((entry != null) && (entry.length > 0)) {
for (int i = 0; i < entry.length; i++) {
if (!supressEntry(entry[i])) {
try {
File tmpFile = new File(directory + File.separator + entry[i]);
if (tmpFile.isDirectory()) {
String pack = truncate(entry[i]);
if (pack.length() > 0) {
foundTypes.packString(root + File.separator + pack);
result = allTypes(foundTypes, root + File.separator + pack);
}
}
tmpFile = null;
} catch (IOException e) {
throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_7(), e);
}
}
}
}
return result;
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class FileSystemStore method createHierarchy.
/**
* Attempt to build up the object store in the file system dynamically.
* This creates directories as required as new types are added to the
* store. Note that we made sure the root object store was created and
* writable at construction time.
*
* WARNING: on a multi-processor box it is possible that multiple threads may
* try to create the same hierarchy at the same time. What will tend to happen
* is that one thread will succeed and the other(s) will fail. However, if a failed
* thread just assumes that the directory is being created by another thread, then
* we're in trouble, because although this may be the case, the directory structure
* may not have actually been created - it may still be in the process of being
* created. So, we have to err on the side of caution and try to create the directory
* a few times. (This can happen across processes too.)
*/
protected final synchronized boolean createHierarchy(String path) throws ObjectStoreException {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("FileSystemStore.createHierarchy(" + path + ")");
}
if ((path != null) && (path.length() > 0)) {
File f = null;
if (path.charAt(path.length() - 1) != File.separatorChar) {
int index = path.lastIndexOf(File.separator);
if (index <= 0)
return true;
else
f = new File(path.substring(0, index));
} else
f = new File(path);
int retryLimit = FileSystemStore.createRetry;
do {
if (f.exists()) {
return true;
} else {
if (!f.mkdirs()) {
retryLimit--;
if (retryLimit == 0)
return false;
try {
Thread.currentThread().sleep(FileSystemStore.createTimeout);
} catch (Exception ex) {
}
} else
return true;
}
} while (!f.exists() && (retryLimit > 0));
return f.exists();
} else
throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_8());
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method read_state.
/**
* Shouldn't be called during normal execution only during recovery.
*/
protected InputObjectState read_state(Uid u, String tn, int s) throws ObjectStoreException {
/*
* In case of asynchronous removals of state, let's trigger the purger
* thread to flush its cache now. Try to avoid false positives during
* recovery wherever possible!
*/
_purger.trigger();
/*
* It's possible that recovery got hold of a state id while it was
* being deleted (marker written and pruning thread not yet active).
* In which case when it comes to do a read it's not going to find
* the state there any longer. Conversely it's possible that it could do
* a read on a state that is about to be deleted. Recovery should be
* able to cope with these edge cases.
*/
TransactionData td = getLogName(u, tn, -1);
if (td == null)
throw new ObjectStoreException();
ArrayList<InputObjectState> states = scanLog(td.container.getName(), tn);
if ((states == null) || (states.size() == 0))
return null;
for (int i = 0; i < states.size(); i++) {
if (states.get(i).stateUid().equals(u))
return states.get(i);
}
return null;
}
use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.
the class LogStore method truncateLog.
/*
* Return true if the log needs to be deleted.
*/
private final boolean truncateLog(final LogInstance log, boolean force) throws ObjectStoreException {
boolean delete = false;
synchronized (_lock) {
File fd = new File(genPathName(log.getName(), log.getTypeName(), StateStatus.OS_COMMITTED));
try {
/*
* Create a list of ObjectState entries.
*/
ArrayList<InputObjectState> objectStates = scanLog(log.getName(), log.getTypeName());
if ((objectStates != null) && (objectStates.size() > 0)) {
/*
* If we are terminating then we can truncate the log to the
* real size needed to contain the existing entries since we
* will not use it again within another VM except for
* recovery purposes.
*/
String fname = genPathName(log.getName(), log.getTypeName(), StateStatus.OS_UNCOMMITTED);
File fd2 = openAndLock(fname, FileLock.F_WRLCK, true);
RandomAccessFile oFile = new RandomAccessFile(fd2, FILE_MODE);
int size = 0;
oFile.setLength(_maxFileSize);
for (int i = 0; i < objectStates.size(); i++) {
byte[] uidString = objectStates.get(i).stateUid().stringForm().getBytes(StandardCharsets.UTF_8);
int buffSize = _redzone.length + uidString.length + objectStates.get(i).buffer().length + 8;
java.nio.ByteBuffer buff = java.nio.ByteBuffer.allocate(buffSize);
size += buffSize;
try {
buff.put(_redzone);
buff.putInt(uidString.length);
buff.put(uidString);
buff.putInt(objectStates.get(i).buffer().length);
buff.put(objectStates.get(i).buffer(), 0, objectStates.get(i).buffer().length);
} catch (final Exception ex) {
ex.printStackTrace();
// TODO log
fd2.delete();
unlockAndClose(fd2, oFile);
throw new ObjectStoreException(ex.toString(), ex);
}
}
try {
if (force) {
oFile.setLength(size);
log.freeze();
}
fd2.renameTo(fd);
} catch (final Exception ex) {
ex.printStackTrace();
throw new ObjectStoreException(ex.toString(), ex);
} finally {
unlockAndClose(fd2, oFile);
}
} else {
/*
* Delete the log if there are no states in it. We could
* keep the file around and reuse it, but the advantage of
* this is small compared to having to cope with reusing old
* log instances.
*/
fd.delete();
/*
* Remember to remove the information from the memory cache.
*/
delete = true;
}
} catch (final ObjectStoreException ex) {
ex.printStackTrace();
throw ex;
} catch (final Exception ex) {
ex.printStackTrace();
throw new ObjectStoreException(ex.toString(), ex);
}
}
return delete;
}
Aggregations