modules/core/nuxeo-core-storage-mongodb/src/main/java/org/nuxeo/ecm/core/storage/mongodb/MongoDBConnection.java
/**
     * Updates the randomized sequence, using xorshift.
     */
Updates the randomized sequence, using xorshift.
Updates the randomized sequence using xorshift .
protected Long tryUpdateRandomizedSequence() {
        long sequenceBlockSize = mongoDBRepository.sequenceBlockSize;
        MongoCollection<Document> countersColl = mongoDBRepository.getCountersCollection();
        Bson filter = Filters.eq(MONGODB_ID, COUNTER_NAME_UUID);
        Document res = countersColl.find(filter).first();
        if (res == null) {
            throw new NuxeoException("Failed to read " + filter + " in collection " + countersColl.getNamespace());
        }
        Long lastValue = res.getLong(COUNTER_FIELD);
        long newValue = xorshift(lastValue, sequenceBlockSize);
        Bson updateFilter = Filters.and( 
                filter, 
                Filters.eq(COUNTER_FIELD, lastValue) 
        );
        Bson update = Updates.set(COUNTER_FIELD, newValue);
        log.trace("MongoDB: FINDANDMODIFY {} UPDATE {}", updateFilter, update);
        boolean updated = countersColl.findOneAndUpdate(updateFilter, update) != null;
        if (updated) {
            return lastValue;
        } else {
            log.trace("MongoDB:    -> FAILED (will retry)");
            return null;
        }
    }
protected Long tryUpdateRandomizedSequence ( ) { long sequenceBlockSize = mongoDBRepository . sequenceBlockSize ; MongoCollection < Document > countersColl = mongoDBRepository . getCountersCollection ( ) ; Bson filter = Filters . eq ( MONGODB_ID , COUNTER_NAME_UUID ) ; Document res = countersColl . find ( filter ) . first ( ) ; if ( res == null ) { throw new NuxeoException ( "Failed to read " + filter + " in collection " + countersColl . getNamespace ( ) ) ; } Long lastValue = res . getLong ( COUNTER_FIELD ) ; long newValue = xorshift ( lastValue , sequenceBlockSize ) ; Bson updateFilter = Filters . and ( filter , Filters . eq ( COUNTER_FIELD , lastValue ) ) ; Bson update = Updates . set ( COUNTER_FIELD , newValue ) ; log . trace ( "MongoDB: FINDANDMODIFY {} UPDATE {}" , updateFilter , update ) ; boolean updated = countersColl . findOneAndUpdate ( updateFilter , update ) != null ; if ( updated ) { return lastValue ; } else { log . trace ( "MongoDB:    -> FAILED (will retry)" ) ; return null ; } }
Updates the randomized sequence, using xorshift.
Updates the randomized sequence using xorshift .
// find the current value // find the next value after this block is done // store the next value for whoever needs it next // // //