Package org.exist.storage.lock

Examples of org.exist.storage.lock.Lock


     */
    //TODO : note that this is *not* this.doc -pb
    public void dropIndex( DocumentImpl document ) throws ReadOnlyException
    {
        final int  collectionId = document.getCollection().getId();
        final Lock lock         = dbValues.getLock();

        try {
            lock.acquire( Lock.WRITE_LOCK );

            for( int section = 0; section <= IDX_QNAME; section++ ) {

                for( final Map.Entry<Object, List<NodeId>> entry : pending[section].entrySet() ) {
                    final Object    key   = entry.getKey();

                    //Compute a key for the indexed value in the collection
                    Value     v;

                    if( section == IDX_GENERIC ) {
                        v = new SimpleValue( collectionId, ( Indexable )key );
                    } else {
                        final QNameKey qnk = ( QNameKey )key;
                        v = new QNameValue( collectionId, qnk.qname, qnk.value, broker.getBrokerPool().getSymbols() );
                    }
                    final Value value = dbValues.get( v );

                    if( value == null ) {
                        continue;
                    }
                    final VariableByteArrayInput is      = new VariableByteArrayInput( value.getData() );
                    boolean                changed = false;
                    os.clear();

                    while( is.available() > 0 ) {
                        final int storedDocId = is.readInt();
                        final int gidsCount   = is.readInt();
                        final int size        = is.readFixedInt();

                        if( storedDocId != document.getDocId() ) {

                            // data are related to another document:
                            // copy them (keep them)
                            os.writeInt( storedDocId );
                            os.writeInt( gidsCount );
                            os.writeFixedInt( size );
                            is.copyRaw( os, size );
                        } else {

                            // data are related to our document:
                            // skip them (remove them)
                            is.skipBytes( size );
                            changed = true;
                        }
                    }

                    //Store new data, if relevant
                    if( changed ) {

                        if( os.data().size() == 0 ) {

                            // nothing to store:
                            // remove the existing key/value pair
                            dbValues.remove( v );
                        } else {

                            // still something to store:
                            // modify the existing value for the key
                            if( dbValues.put( v, os.data() ) == BFile.UNKNOWN_ADDRESS ) {
                                LOG.error( "Could not put index data for key '" + v + "'" );
                                //TODO : throw exception ?
                            }
                        }
                    }
                }
                pending[section].clear();
            }
        }
        catch( final LockException e ) {
            LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
        }
        catch( final IOException e ) {
            LOG.error( e.getMessage(), e );
        }
        catch( final EXistException e ) {
            LOG.warn( "Exception while removing range index: " + e.getMessage(), e );
        }
        finally {
            os.clear();
            lock.release( Lock.WRITE_LOCK );
        }
    }
View Full Code Here


     * @throws  TerminatedException  DOCUMENT ME!
     */
    private NodeSet findAll(XQueryWatchDog watchDog, int relation, DocumentSet docs, NodeSet contextSet, int axis, List<QName> qnames, Indexable value, NodeSet result, Collator collator ) throws TerminatedException
    {
        final SearchCallback cb   = new SearchCallback( docs, contextSet, result, axis == NodeSet.ANCESTOR );
        final Lock           lock = dbValues.getLock();

        for( final Iterator<Collection> iter = docs.getCollectionIterator(); iter.hasNext(); ) {
            final int collectionId = iter.next().getId();
            final int idxOp        = checkRelationOp( relation );
            Value     searchKey;
            Value     prefixKey;

            watchDog.proceed(null);

            if( qnames == null ) {

                try {
                    lock.acquire( Lock.READ_LOCK );
                    searchKey = new SimpleValue( collectionId, value );
                    prefixKey = new SimplePrefixValue( collectionId, value.getType() );
                    final IndexQuery query = new IndexQuery( idxOp, searchKey );

                    if( idxOp == IndexQuery.EQ ) {
                        dbValues.query( query, cb );
                    } else {
                        dbValues.query( query, prefixKey, cb );
                    }
                }
                catch( final EXistException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final LockException e ) {
                    LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
                }
                catch( final IOException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final BTreeException e ) {
                    LOG.error( e.getMessage(), e );
                }
                finally {
                    lock.release( Lock.READ_LOCK );
                }
            } else {

                for( int i = 0; i < qnames.size(); i++ ) {
                    final QName qname = ( QName )qnames.get( i );

                    try {
                        lock.acquire( Lock.READ_LOCK );

                        //Compute a key for the value in the collection
                        searchKey = new QNameValue( collectionId, qname, value, broker.getBrokerPool().getSymbols() );
                        prefixKey = new QNamePrefixValue( collectionId, qname, value.getType(), broker.getBrokerPool().getSymbols() );

                        final IndexQuery query = new IndexQuery( idxOp, searchKey );

                        if( idxOp == IndexQuery.EQ ) {
                            dbValues.query( query, cb );
                        } else {
                            dbValues.query( query, prefixKey, cb );
                        }
                    }
                    catch( final EXistException e ) {
                        LOG.error( e.getMessage(), e );
                    }
                    catch( final LockException e ) {
                        LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
                    }
                    catch( final IOException e ) {
                        LOG.error( e.getMessage(), e );
                    }
                    catch( final BTreeException e ) {
                        LOG.error( e.getMessage(), e );
                    }
                    finally {
                        lock.release( Lock.READ_LOCK );
                    }
                }
            }
        }
        return( result );
View Full Code Here

        } else {
            matcher = new CollatorMatcher( expr, truncation, collator );
        }

        final MatcherCallback cb   = new MatcherCallback( docs, contextSet, result, matcher, axis == NodeSet.ANCESTOR );
        final Lock            lock = dbValues.getLock();

        for( final Iterator<Collection> iter = docs.getCollectionIterator(); iter.hasNext(); ) {
            final int collectionId = iter.next().getId();
            Value     searchKey;

            watchDog.proceed(null);
            if( qnames == null ) {

                try {
                    lock.acquire( Lock.READ_LOCK );

                    if( startTerm != null ) {

                        //Compute a key for the start term in the collection
                        searchKey = new SimpleValue( collectionId, startTerm );
                    } else {

                        //Compute a key for an arbitrary string in the collection
                        searchKey = new SimplePrefixValue( collectionId, Type.STRING );
                    }
                    final IndexQuery query = new IndexQuery( IndexQuery.TRUNC_RIGHT, searchKey );
                    dbValues.query( query, cb );
                }
                catch( final LockException e ) {
                    LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
                }
                catch( final IOException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final BTreeException e ) {
                    LOG.error( e.getMessage(), e );
                }
                finally {
                    lock.release( Lock.READ_LOCK );
                }
            } else {

                for( int i = 0; i < qnames.size(); i++ ) {
                    final QName qname = ( QName )qnames.get( i );

                    try {
                        lock.acquire( Lock.READ_LOCK );

                        if( startTerm != null ) {
                            searchKey = new QNameValue( collectionId, qname, startTerm, broker.getBrokerPool().getSymbols() );
                        } else {
                            LOG.debug( "Searching with QName prefix" );
                            searchKey = new QNamePrefixValue( collectionId, qname, Type.STRING, broker.getBrokerPool().getSymbols() );
                        }
                        final IndexQuery query = new IndexQuery( IndexQuery.TRUNC_RIGHT, searchKey );
                        dbValues.query( query, cb );
                    }
                    catch( final LockException e ) {
                        LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
                    }
                    catch( final IOException e ) {
                        LOG.error( e.getMessage(), e );
                    }
                    catch( final BTreeException e ) {
                        LOG.error( e.getMessage(), e );
                    }
                    finally {
                        lock.release( Lock.READ_LOCK );
                    }
                }
            }
        }
        return( result );
View Full Code Here

    public ValueOccurrences[] scanIndexKeys( DocumentSet docs, NodeSet contextSet, Indexable start )
    {
        final int               type       = start.getType();
        final boolean           stringType = Type.subTypeOf( type, Type.STRING );
        final IndexScanCallback cb         = new IndexScanCallback( docs, contextSet, type, false );
        final Lock              lock       = dbValues.getLock();

        for( final Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext(); ) {

            try {
                lock.acquire( Lock.READ_LOCK );
                final Collection c            = ( Collection )i.next();
                final int        collectionId = c.getId();

                //Compute a key for the start value in the collection
                if( stringType ) {
                    final Value startKey = new SimpleValue( collectionId, start );
                    final IndexQuery  query    = new IndexQuery( IndexQuery.TRUNC_RIGHT, startKey );
                    dbValues.query( query, cb );
                } else {
                    final Value      startKey  = new SimpleValue( collectionId, start );
                    final Value      prefixKey = new SimplePrefixValue( collectionId, start.getType() );
                    final IndexQuery query     = new IndexQuery( IndexQuery.GEQ, startKey );
                    dbValues.query( query, prefixKey, cb );
                }
            }
            catch( final EXistException e ) {
                LOG.error( e.getMessage(), e );
            }
            catch( final LockException e ) {
                LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
            }
            catch( final IOException e ) {
                LOG.error( e.getMessage(), e );
            }
            catch( final BTreeException e ) {
                LOG.error( e.getMessage(), e );
            }
            catch( final TerminatedException e ) {
                LOG.warn( e.getMessage(), e );
            }
            finally {
                lock.release( Lock.READ_LOCK );
            }
        }
        final Map<AtomicValue, ValueOccurrences> map = cb.map;
        final ValueOccurrences[] result = new ValueOccurrences[map.size()];
        return( ( ValueOccurrences[] )map.values().toArray( result ) );
View Full Code Here

            qnames = ( QName[] )qnlist.toArray( qnames );
        }
        final int               type       = start.getType();
        final boolean           stringType = Type.subTypeOf( type, Type.STRING );
        final IndexScanCallback cb         = new IndexScanCallback( docs, contextSet, type, true );
        final Lock              lock       = dbValues.getLock();

        for( int j = 0; j < qnames.length; j++ ) {

            for( final Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext(); ) {

                try {
                    lock.acquire( Lock.READ_LOCK );
                    final int collectionId = ( ( Collection )i.next() ).getId();

                    //Compute a key for the start value in the collection
                    if( stringType ) {
                        final Value startKey = new QNameValue( collectionId, qnames[j], start, broker.getBrokerPool().getSymbols() );
                        final IndexQuery  query    = new IndexQuery( IndexQuery.TRUNC_RIGHT, startKey );
                        dbValues.query( query, cb );
                    } else {
                        final Value      startKey  = new QNameValue( collectionId, qnames[j], start, broker.getBrokerPool().getSymbols() );
                        final Value      prefixKey = new QNamePrefixValue( collectionId, qnames[j], start.getType(), broker.getBrokerPool().getSymbols() );
                        final IndexQuery query     = new IndexQuery( IndexQuery.GEQ, startKey );
                        dbValues.query( query, prefixKey, cb );
                    }
                }
                catch( final EXistException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final LockException e ) {
                    LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
                }
                catch( final IOException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final BTreeException e ) {
                    LOG.error( e.getMessage(), e );
                }
                catch( final TerminatedException e ) {
                    LOG.warn( e.getMessage(), e );
                }
                finally {
                    lock.release( Lock.READ_LOCK );
                }
            }
        }
        final Map<AtomicValue, ValueOccurrences> map = cb.map;
        final ValueOccurrences[] result = new ValueOccurrences[map.size()];
View Full Code Here

        int tries = 0;
        do {
            final Cacheable cached = next.getValue();
            if(cached.getKey() != item.getKey()) {
                final Collection old = (Collection) cached;
                final Lock lock = old.getLock();
                if (lock.attempt(Lock.READ_LOCK)) {
                    try {
                        if (cached.allowUnload()) {
                            if(pool.getConfigurationManager()!=null) { // might be null during db initialization
                                pool.getConfigurationManager().invalidate(old.getURI(), null);
                            }
                            names.remove(old.getURI().getRawCollectionPath());
                            cached.sync(true);
                            map.remove(cached.getKey());
                            removed = true;
                        }
                    } finally {
                        lock.release(Lock.READ_LOCK);
                    }
                }
            }
            if (!removed) {
                next = next.getNext();
View Full Code Here

TOP

Related Classes of org.exist.storage.lock.Lock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.