Search in sources :

Example 1 with ReadonlyTableStore

use of net.openhft.chronicle.queue.impl.table.ReadonlyTableStore in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueBuilder method initializeMetadata.

protected void initializeMetadata() {
    File metapath = metapath();
    validateRollCycle(metapath);
    SCQMeta metadata = new SCQMeta(new SCQRoll(rollCycle(), epoch(), rollTime, rollTimeZone), deltaCheckpointInterval(), sourceId());
    try {
        boolean readOnly = readOnly();
        metaStore = SingleTableBuilder.binary(metapath, metadata).readOnly(readOnly).build();
        // check if metadata was overridden
        SCQMeta newMeta = metaStore.metadata();
        sourceId(newMeta.sourceId());
        String format = newMeta.roll().format();
        if (!format.equals(rollCycle().format())) {
            // roll cycle changed
            overrideRollCycleForFileName(format);
        }
        // if it was overridden - reset
        rollTime = newMeta.roll().rollTime();
        rollTimeZone = newMeta.roll().rollTimeZone();
        epoch = newMeta.roll().epoch();
    } catch (IORuntimeException ex) {
        // readonly=true and file doesn't exist
        if (OS.isWindows())
            // we cant have a read-only table store on windows so we have no option but to throw the ex.
            throw ex;
        if (ex.getMessage().equals("Metadata file not found in readOnly mode"))
            Jvm.warn().on(getClass(), "Failback to readonly tablestore " + ex);
        else
            Jvm.warn().on(getClass(), "Failback to readonly tablestore", ex);
        metaStore = new ReadonlyTableStore<>(metadata);
    }
}
Also used : ReadonlyTableStore(net.openhft.chronicle.queue.impl.table.ReadonlyTableStore) IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) File(java.io.File)

Aggregations

File (java.io.File)1 IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)1 ReadonlyTableStore (net.openhft.chronicle.queue.impl.table.ReadonlyTableStore)1