Search in sources :

Example 1 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class TransactionLog method getIds.

/**
 * Get a list object ids for a given object type
 *
 * @param ids holder for the returned uids
 * @param objectType The type of object to search in the recoveryStore for
 * @return all objects of the given type
 * @throws ObjectStoreException the recoveryStore implementation was unable retrieve all types of objects
 */
public Collection<Uid> getIds(Collection<Uid> ids, String objectType) throws ObjectStoreException {
    if (ids == null)
        ids = new ArrayList<Uid>();
    InputObjectState types = new InputObjectState();
    if (recoveryStore.allTypes(types)) {
        String theName;
        try {
            boolean endOfList = false;
            while (!endOfList) {
                theName = types.unpackString();
                if (theName.compareTo("") == 0)
                    endOfList = true;
                else {
                    if (objectType != null && !theName.equals(objectType))
                        continue;
                    InputObjectState uids = new InputObjectState();
                    if (recoveryStore.allObjUids(theName, uids)) {
                        Uid theUid = new Uid(Uid.nullUid());
                        try {
                            boolean endOfUids = false;
                            while (!endOfUids) {
                                theUid = UidHelper.unpackFrom(uids);
                                if (theUid.equals(Uid.nullUid()))
                                    endOfUids = true;
                                else
                                    ids.add(theUid);
                            }
                        } catch (Exception e) {
                        // end of uids!
                        }
                    }
                    System.out.println();
                }
            }
        } catch (Exception e) {
            System.err.println(e);
        // end of list!
        }
    }
    return ids;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ArrayList(java.util.ArrayList) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 2 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class RecoveryManager method recoverParticipants.

private void recoverParticipants() {
    if (ParticipantsManagerFactory.getInstance().getBaseUrl() != null) {
        final RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        final InputObjectState states = new InputObjectState();
        try {
            if (recoveryStore.allObjUids(PARTICIPANT_INFORMATION_RECORD_TYPE, states)) {
                Uid uid;
                while ((uid = UidHelper.unpackFrom(states)).notEquals(Uid.nullUid())) {
                    final ParticipantInformation participantInformation = recreateParticipantInformation(recoveryStore, uid);
                    if (participantInformation != null) {
                        ParticipantsContainer.getInstance().addParticipantInformation(participantInformation.getId(), participantInformation);
                    }
                }
            }
        } catch (ObjectStoreException e) {
            LOG.warn(e.getMessage(), e);
        } catch (IOException e) {
            LOG.warn(e.getMessage(), e);
        }
    } else {
        LOG.warn("Participants cannot be loaded from the object store, because base URL was not set.");
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 3 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class ShadowingStore method read_state.

protected InputObjectState read_state(Uid objUid, String tName, int ft) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("ShadowingStore.read_state(" + objUid + ", " + tName + ", " + StateType.stateTypeString(ft) + ")");
    }
    InputObjectState new_image = null;
    if (tName != null) {
        int state = currentState(objUid, tName);
        if ((state == StateStatus.OS_COMMITTED) || (state == StateStatus.OS_UNCOMMITTED)) {
            if (((state == StateStatus.OS_COMMITTED) && (ft != StateType.OS_ORIGINAL)) || ((state == StateStatus.OS_UNCOMMITTED) && (ft != StateType.OS_SHADOW))) {
                /*
                     * Print out a warning/info if the state has changed to help explain the null
                     * value that is returned.
                     */
                tsLogger.logger.info("Object state " + objUid + " for type " + tName + " has changed on disk from what was expected.");
                return null;
            }
            String fname = genPathName(objUid, tName, ft);
            File fd = openAndLock(fname, FileLock.F_RDLCK, false);
            if (fd != null) {
                int imageSize = (int) fd.length();
                byte[] buffer = new byte[imageSize];
                FileInputStream ifile = null;
                try {
                    ifile = new FileInputStream(fd);
                } catch (FileNotFoundException e) {
                    closeAndUnlock(fd, ifile, null);
                    tsLogger.logger.info("ObjectStore record was deleted during restoration, users should not deleted records manually: " + fd.getAbsolutePath(), e);
                    return null;
                }
                try {
                    if ((buffer != null) && (ifile.read(buffer, 0, imageSize) == imageSize)) {
                        new_image = new InputObjectState(objUid, tName, buffer);
                    } else {
                        tsLogger.i18NLogger.warn_objectstore_ShadowingStore_7();
                    }
                } catch (IOException e) {
                    closeAndUnlock(fd, ifile, null);
                    throw new ObjectStoreException("ShadowingStore::read_state failed: " + e, e);
                }
                if (!closeAndUnlock(fd, ifile, null)) {
                    tsLogger.i18NLogger.warn_objectstore_ShadowingStore_8(fname);
                }
            } else {
                tsLogger.i18NLogger.warn_objectstore_ShadowingStore_5(fname);
            }
        } else {
            if (tsLogger.logger.isTraceEnabled())
                tsLogger.logger.trace("ShadowingStore.read_state could not find committed or uncommitted state for " + objUid + " instead found state " + StateStatus.stateStatusString(state));
        }
    } else
        throw new ObjectStoreException("ShadowStore::read_state - " + tsLogger.i18NLogger.get_objectstore_notypenameuid() + objUid);
    return new_image;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class ShadowingStore method commit_state.

/**
 * Commit a previous write_state operation which was made with the SHADOW
 * StateType argument. This is achieved by renaming the shadow and removing
 * the hidden version.
 */
public boolean commit_state(Uid objUid, String tName) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("ShadowingStore.commit_state(" + objUid + ", " + tName + ")");
    }
    boolean result = false;
    if (tName != null) {
        String shadow = null;
        String filename = null;
        int state = currentState(objUid, tName);
        if ((state == StateStatus.OS_UNCOMMITTED_HIDDEN) || (state == StateStatus.OS_UNCOMMITTED)) {
            shadow = genPathName(objUid, tName, StateType.OS_SHADOW);
            filename = genPathName(objUid, tName, StateType.OS_ORIGINAL);
            if (state == StateStatus.OS_UNCOMMITTED_HIDDEN) {
                /* maintain hidden status on rename */
                shadow = shadow + HIDDINGCHAR;
                filename = filename + HIDDINGCHAR;
            }
            File shadowState = new File(shadow);
            File originalState = new File(filename);
            /*
                 * We need to do this because rename will not overwrite an
                 * existing file in Windows, as it will in Unix. It is safe to
                 * do so since we have written the shadow.
                 */
            result = renameFromTo(shadowState, originalState);
            if (!result) {
                tsLogger.i18NLogger.warn_objectstore_ShadowingStore_2(shadow, filename);
            } else {
                super.addToCache(filename);
                super.removeFromCache(shadow);
            }
            shadowState = null;
            originalState = null;
        } else
            result = true;
    } else
        throw new ObjectStoreException("ShadowStore::commit_state - " + tsLogger.i18NLogger.get_objectstore_notypenameuid() + objUid);
    return result;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) File(java.io.File)

Example 5 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class ShadowingStore method write_state.

/**
 * write_state saves the ObjectState in a file named by the type and Uid of
 * the ObjectState. If the second argument is SHADOW, then the file name is
 * different so that a subsequent commit_state invocation will rename the
 * file.
 */
protected boolean write_state(Uid objUid, String tName, OutputObjectState state, int ft) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("ShadowingStore.write_state(" + objUid + ", " + tName + ", " + StateType.stateTypeString(ft) + ")");
    }
    if (tName != null) {
        String fname = genPathName(objUid, tName, ft);
        File fd = openAndLock(fname, FileLock.F_WRLCK, true);
        int imageSize = (int) state.length();
        if (fd == null) {
            tsLogger.i18NLogger.warn_objectstore_ShadowingStore_18(fname);
            return false;
        }
        FileOutputStream ofile = null;
        if (imageSize > 0) {
            try {
                ofile = new FileOutputStream(fd);
                ofile.write(state.buffer(), 0, imageSize);
                if (synchronousWrites()) {
                    // must flush any in-memory buffering prior to sync
                    ofile.flush();
                    // assume it's
                    FileDescriptor fileDesc = ofile.getFD();
                    // valid!
                    fileDesc.sync();
                }
            } catch (SyncFailedException e) {
                closeAndUnlock(fd, null, ofile);
                throw new ObjectStoreException("ShadowingStore::write_state() - write failed to sync for " + fname, e);
            } catch (FileNotFoundException e) {
                closeAndUnlock(fd, null, ofile);
                e.printStackTrace();
                throw new ObjectStoreException("ShadowingStore::write_state() - write failed to locate file " + fname + ": " + e, e);
            } catch (IOException e) {
                closeAndUnlock(fd, null, ofile);
                e.printStackTrace();
                throw new ObjectStoreException("ShadowingStore::write_state() - write failed for " + fname + ": " + e, e);
            }
        }
        if (!closeAndUnlock(fd, null, ofile)) {
            tsLogger.i18NLogger.warn_objectstore_ShadowingStore_19(fname);
        }
        super.addToCache(fname);
        return true;
    } else
        throw new ObjectStoreException("ShadowStore::write_state - " + tsLogger.i18NLogger.get_objectstore_notypenameuid() + objUid);
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) SyncFailedException(java.io.SyncFailedException) IOException(java.io.IOException) File(java.io.File) FileDescriptor(java.io.FileDescriptor)

Aggregations

ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)87 IOException (java.io.IOException)44 Uid (com.arjuna.ats.arjuna.common.Uid)35 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)34 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)23 File (java.io.File)11 Connection (java.sql.Connection)9 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 NamingException (javax.naming.NamingException)9 Enumeration (java.util.Enumeration)8 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)6 FileNotFoundException (java.io.FileNotFoundException)5 ResultSet (java.sql.ResultSet)5 ArrayList (java.util.ArrayList)5 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)4 XidImple (com.arjuna.ats.jta.xa.XidImple)4 RandomAccessFile (java.io.RandomAccessFile)3 SyncFailedException (java.io.SyncFailedException)3 Statement (java.sql.Statement)3