Package com.fasterxml.storemate.store

Examples of com.fasterxml.storemate.store.StorableStore


   
    private void _testOverwrite(String name, boolean expSuccess, OverwriteChecker checker)
        throws Exception
    {
        TimeMasterForSimpleTesting timeMaster = new TimeMasterForSimpleTesting(START_TIME_0);
        StorableStore store = createStore("bdb-"+name, timeMaster);
        final StorableKey KEY1 = storableKey("data/overwrite1");
        // big enough not to get inlined
        final byte[] DATA_ORIG = biggerCompressibleData(200 * 1000).getBytes("UTF-8");
        final byte[] CUSTOM_METADATA_ORIG = new byte[] { 'a', 'b', 'c', 'd' };

        final byte[] DATA_REPLACE = biggerCompressibleData(190 * 1000).getBytes("UTF-8");
        final byte[] CUSTOM_METADATA_REPLACE = new byte[] { 'd', 'e' };
       
        try {
            StorableCreationMetadata metadata = new StorableCreationMetadata(null,
                            calcChecksum32(DATA_ORIG), HashConstants.NO_CHECKSUM);
            metadata.uncompressedSize = -1L;
            StorableCreationResult resp = store.insert(StoreOperationSource.REQUEST, null,
                    KEY1, new ByteArrayInputStream(DATA_ORIG),
                    metadata, ByteContainer.simple(CUSTOM_METADATA_ORIG));
            assertTrue(resp.succeeded());
           
            assertNull(resp.getPreviousEntry());
            _verifyCounts(1L, store);

            // Then try to overwrite with a newer timestamp
            timeMaster.advanceCurrentTimeMillis(1000);

            StorableCreationMetadata metadata2 = new StorableCreationMetadata(null,
                    calcChecksum32(DATA_REPLACE), HashConstants.NO_CHECKSUM);
            metadata.uncompressedSize = -1L;
            resp = store.upsertConditionally(StoreOperationSource.REQUEST, null,
                    KEY1, new ByteArrayInputStream(DATA_REPLACE),
                    metadata2, ByteContainer.simple(CUSTOM_METADATA_REPLACE),
                    true, checker);

            _verifyCounts(1L, store);

            final Storable oldEntry = resp.getPreviousEntry();
            assertNotNull(oldEntry);
            assertTrue(oldEntry.hasExternalData());
           
            if (expSuccess) { // yes, ought to overwrite:
                assertTrue("Should succeeed with checker "+checker, resp.succeeded());
            } else { // nope, original retained
                assertFalse("Should fail with checker "+checker, resp.succeeded());
            }

            // and then verify
            Storable entry = store.findEntry(StoreOperationSource.REQUEST, null, KEY1);
            assertNotNull(entry);
            assertFalse(entry.hasInlineData());
            assertTrue(entry.hasExternalData());
            assertEquals(Compression.LZF, entry.getCompression());

            if (expSuccess) {
                assertEquals(START_TIME_0 + 1000L, entry.getLastModified());
                assertEquals(DATA_REPLACE.length, entry.getOriginalLength());
                assertEquals(DATA_REPLACE.length, entry.getActualUncompressedLength());
                _verifyMetadata(entry, CUSTOM_METADATA_REPLACE);
            } else {
                assertEquals(START_TIME_0, entry.getLastModified());
                assertEquals(DATA_ORIG.length, entry.getOriginalLength());
                assertEquals(DATA_ORIG.length, entry.getActualUncompressedLength());
                _verifyMetadata(entry, CUSTOM_METADATA_ORIG);
            }
            // and read the contents
            File f = entry.getExternalFile(store.getFileManager());
            if (!f.exists()) {
                fail("File '"+f.getAbsolutePath()+"' (replacement? "+expSuccess+") should exist, does not");
            }
            byte[] b = readFile(f);
            byte[] uncomp = Compressors.lzfUncompress(b);
           
            if (expSuccess) {
                assertEquals(DATA_REPLACE.length, uncomp.length);
            } else {
                assertEquals(DATA_ORIG.length, uncomp.length);
            }

            // And finally, verify that old file is gone, if replacement succeeded
            if (expSuccess) {
                File oldFile = oldEntry.getExternalFile(store.getFileManager());
                if (oldFile.exists()) {
                    fail("Should have deleted old file '"+oldFile.getAbsolutePath()+"' ("
                            +oldFile.length()+" bytes)");
                }
            }
            // Regardless, should have one and only one storage file remaining.
            File dir = store.getFileManager().dataRootForTesting();
            List<String> filenames = new ArrayList<String>();
            _findFiles(dir, filenames);
            if (filenames.size() != 1) {
                fail("Should only have 1 store file after operations, got "+filenames.size()+": "+filenames);
            }
         } finally {
            store.stop();
        }
    }
View Full Code Here


   
    protected SyncListResponse<E> _listEntries(final KeyRange inRange,
            final long since, long upTo0, final int maxCount)
        throws InterruptedException, StoreException
    {
        final StorableStore store = _stores.getEntryStore();
        final ArrayList<E> result = new ArrayList<E>(Math.min(100, maxCount));
        long lastSeenTimestamp = 0L;
        long clientWait = 0L; // we may instruct client to do bit of waiting before retry
       
        // let's only allow single wait; hence two rounds
        for (int round = 0; round < 2; ++round) {
            /* 19-Sep-2012, tatu: Alas, it is difficult to make this work with virtual time,
             *   tests; so for now we will use actual real system time and not virtual time.
             *   May need to revisit in future.
             */
            final long realStartTime = _timeMaster.realSystemTimeMillis();
            if (upTo0 >= realStartTime) { // sanity check (better safe than sorry)
                throw new IllegalStateException("Argument 'upTo' too high ("+upTo0+"): can not exceed current time ("
                        +realStartTime);
            }
            /* one more thing: need to make sure we can skip entries that
             * have been updated concurrently (rare, but possible).
             */
            long oldestInFlight = store.getOldestInFlightTimestamp();
            if (oldestInFlight != 0L) {
                if (upTo0 > oldestInFlight) {
                    // since it's rare, add INFO logging to see if ever encounter this
                    LOG.info("Oldest in-flight ({}) higher than upTo ({}), use former as limit",
                            oldestInFlight, upTo0);
View Full Code Here

            LOG.warn("Unrecognized properties in SyncPullRequest: "+requestEntity.unknownProperties());
        }
       
        List<StorableKey> ids = requestEntity.entries;
        ArrayList<E> entries = new ArrayList<E>(ids.size());
        StorableStore store = _stores.getEntryStore();

        try {
            for (StorableKey key : ids) {
                Storable raw = store.findEntry(key);
                // note: this may give null as well; caller needs to check (converter passes null as-is)
                E entry = (E) _entryConverter.entryFromStorable(raw);
                entries.add(entry);
            }
        } catch (StoreException e) {
View Full Code Here

            backendConfig = stuff.convertValue(v.storeBackendConfig, cfgType);
        }
        StoreBackend backend = b.with(v.storeConfig)
                .with(backendConfig)
                .build();
        StorableStore store = new StorableStoreImpl(v.storeConfig, backend, _timeMaster,
               stuff.getFileManager());
        return constructStores(stuff, v, store);
    }
View Full Code Here

            LOG.warn("Unrecognized properties in SyncPullRequest: "+requestEntity.unknownProperties());
        }
       
        List<StorableKey> ids = requestEntity.entries;
        ArrayList<E> entries = new ArrayList<E>(ids.size());
        StorableStore store = _stores.getEntryStore();

        try {
            for (StorableKey key : ids) {
                // null -> let's not pass 'metadata' yet since we don't use timings?
                Storable raw = store.findEntry(StoreOperationSource.SYNC, null, key);
                // note: this may give null as well; caller needs to check (converter passes null as-is)
                E entry = (E) _entryConverter.entryFromStorable(raw);
                entries.add(entry);
            }
        } catch (StoreException e) {
View Full Code Here

   
    protected SyncListResponse<E> _listEntries(final KeyRange inRange,
            final long since, final int maxCount)
        throws InterruptedException, StoreException
    {
        final StorableStore store = _stores.getEntryStore();
        final ArrayList<E> result = new ArrayList<E>(Math.min(100, maxCount));
        long lastSeenTimestamp = 0L;
        long clientWait = 0L; // we may instruct client to do bit of waiting before retry
       
        // let's only allow single wait; hence two rounds
        long upTo0 = 0;
        for (int round = 0; round < 2; ++round) {
            upTo0 = _timeMaster.currentTimeMillis() - _cfgSyncGracePeriodMsecs;

            /* 19-Sep-2012, tatu: Alas, it is difficult to make this work with virtual time,
             *   tests; so for now we will use actual real system time and not virtual time.
             *   May need to revisit in future.
             */
            final long realStartTime = _timeMaster.realSystemTimeMillis();
            if (upTo0 >= realStartTime) { // sanity check (better safe than sorry)
                throw new IllegalStateException("Argument 'upTo' too high ("+upTo0+"): can not exceed current time ("
                        +realStartTime);
            }
            /* one more thing: need to make sure we can skip entries that
             * have been updated concurrently (rare, but possible).
             */
            long oldestInFlight = store.getOldestInFlightTimestamp();
            if (oldestInFlight != 0L) {
                if (upTo0 > oldestInFlight) {
                    // since it's rare, add INFO logging to see if ever encounter this
                    LOG.info("Oldest in-flight ({}) higher than upTo ({}), use former as limit",
                            oldestInFlight, upTo0);
View Full Code Here

            backendConfig = stuff.convertValue(v.storeBackendConfig, cfgType);
        }
        StoreBackend backend = b.with(v.storeConfig)
                .with(backendConfig)
                .build();
        StorableStore store = new StorableStoreImpl(v.storeConfig, backend, _timeMaster,
               stuff.getFileManager());
        return constructStores(stuff, v, store);
    }
View Full Code Here

            backendConfig = stuff.convertValue(v.storeBackendConfig, cfgType);
        }
        StoreBackend backend = b.with(v.storeConfig)
                .with(backendConfig)
                .build();
        StorableStore store = new StorableStoreImpl(v.storeConfig, backend, _timeMaster,
               stuff.getFileManager());
        return constructStores(stuff, v, store);
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.storemate.store.StorableStore

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.