/** * Gets whether the location is lockable i.e. is it an on-disk location * where we can use a lock file to prevent multi-process access and the * potential data corruption that ensues * * @return True if the location is lockable */ public boolean canLock() { return !location.isMem(); }
/** Test whether a location already has a TDB database or whether a call to TDBFactory * will cause a new, fresh TDB database to be created (pragmatic tests). * The directory may be empty, or not exist. * Existing databases return "true". */ public static boolean inUseLocation(Location location) { if ( location.isMemUnique() ) return false ; if ( location.isMem() ) return StoreConnection.getExisting(location) != null ; String dirname = location.getDirectoryPath() ; File d = new File(dirname) ; if ( ! d.exists() ) // TDB autocreates directories one level. return ! FileOps.exists(d.getParent()) ; return ! TDBInternal.isNewDatabaseArea(location) ; }
public boolean isMem() { return location.isMem() ; }
public boolean exists(String ext) { if ( location.isMem() ) return true ; String fn = filename(ext) ; File f = new File(fn) ; if ( f.isDirectory() ) log.warn("File clashes with a directory") ; return f.exists() && f.isFile() ; }
/** * Gets whether the location is currently locked * * @return boolean */ public boolean isLocked() { // Memory locations are never considered locked if (location.isMem()) return false; return getOwner() != NO_OWNER; }
private void ensure(String dirname) { if ( isMem() ) return ; File file = new File(dirname) ; if ( file.exists() && !file.isDirectory() ) throw new FileException("Existing file: " + file.getAbsolutePath()) ; if ( !file.exists() ) file.mkdir() ; }
private String fixupName(String fsName) { if ( isMem() ) return fsName ; File file = new File(fsName) ; try { fsName = file.getCanonicalPath() ; } catch (IOException ex) { throw new FileException("Failed to get canoncial path: " + file.getAbsolutePath(), ex) ; } if ( !fsName.endsWith(File.separator) && !fsName.endsWith(pathSeparator) ) fsName = fsName + pathSeparator ; return fsName ; }
/** Look at a directory and see if it is a new area */ public static boolean isNewDatabaseArea(Location location) { StoreConnection sConn = StoreConnection.getExisting(location) ; if ( sConn != null ) // Already has a StoreConnection return false ; if ( location.isMem() ) return true ; File d = new File(location.getDirectoryPath()) ; if ( !d.exists() ) return true ; FileFilter ff = fileFilterNewDB ; File[] entries = d.listFiles(ff) ; return entries.length == 0 ; }
/** Convert a {@link Location} to a {@link Path}. */ public static Path asPath(Location location) { if ( location.isMem() ) throw new RuntimeIOException("Location is a memory location: "+location); return Paths.get(location.getDirectoryPath()); }
public static boolean exists(Location location) { if ( location.isMem() ) return false ; return FileOps.exists(journalFilename(location)) ; }
/** * Read from a file if possible. * Return null for memory locations, file not found or syntax errors. */ public static StoreParams read(Location location) { if ( location.isMem() ) return null ; return read(location.getPath(TDB_CONFIG_FILE)) ; }
/** * Gets whether the lock is owned by the current process * * @return True if the location is locked and owned by the process, false * otherwise */ public boolean isOwned() { // Memory locations are never considered locked if (location.isMem()) return false; int owner = getOwner(); if (owner == NO_OWNER) return false; return owner == ProcessUtils.getPid(NO_OWNER); }
private static void checkLocation(Location location) { if ( location.isMem() ) return ; String dirname = location.getDirectoryPath() ; File dir = new File(dirname) ; // File location. if ( ! dir.exists() ) error(log, "Does not exist: "+dirname) ; if ( ! dir.isDirectory() ) error(log, "Not a directory: "+dirname) ; if ( ! dir.canRead() ) error(log, "Directory not readable: "+dirname) ; if ( ! dir.canWrite() ) error(log, "Directory not writeable: "+dirname) ; }
private void init() { if ( INITIALIZED ) { checkInit(stateLocation); return; } synchronized(zoneLock) { if ( INITIALIZED ) { checkInit(stateLocation); return; } INITIALIZED = true; if ( stateLocation == null || stateLocation.isMem() ) { // In-memory only. stateArea = null; return ; } stateArea = IOX.asPath(stateLocation); List<Path> x = scanForDataState(stateLocation); x.forEach(p->LOG.info("Connection : "+p)); x.forEach(p->fromOnDiskState(p)); } }
public static Journal create(Location location) { BufferChannel chan ; String channelName = journalFilename(location) ; if ( location.isMem() ) chan = BufferChannelMem.create(channelName) ; else chan = BufferChannelFile.create(channelName) ; return new Journal(chan) ; }
public /* for testing */ static void init$() { if ( initialized ) return ; initialized = true ; if ( location == null ) location = Location.create(FusekiWebapp.dirSystemDatabase.toString()) ; if ( ! location.isMem() ) FileOps.ensureDir(location.getDirectoryPath()) ; // Force it into the store connection as a low footprint if ( StoreConnection.getExisting(location) != null ) Fuseki.serverLog.warn("System database already in the StoreConnection cache") ; StoreConnection.make(location, systemDatabaseParams) ; dataset = TDBFactory.createDataset(location) ; dsg = (DatasetGraphTransaction)(dataset.asDatasetGraph()) ; dsg.getContext().set(TDB.symUnionDefaultGraph, false) ; } }
public /* for testing */ static void init$() { if ( initialized ) return ; initialized = true ; if ( location == null ) location = Location.create(FusekiWebapp.dirSystemDatabase.toString()) ; if ( ! location.isMem() ) FileOps.ensureDir(location.getDirectoryPath()) ; // Force it into the store connection as a low footprint if ( StoreConnection.getExisting(location) != null ) Fuseki.serverLog.warn("System database already in the StoreConnection cache") ; StoreConnection.make(location, systemDatabaseParams) ; dataset = TDBFactory.createDataset(location) ; dsg = (DatasetGraphTransaction)(dataset.asDatasetGraph()) ; dsg.getContext().set(TDB.symUnionDefaultGraph, false) ; } }
@Override final public void finishBulk() { loaderTriples.loadDataFinish() ; loaderTriples.loadIndexStart() ; loaderTriples.loadIndexFinish() ; loaderTriples.loadFinish() ; if ( !dsg.getLocation().isMem() && startedEmpty && stats != null ) { String filename = dsg.getLocation().getPath(Names.optStats) ; Stats.write(filename, stats.results()) ; } forceSync(dsg) ; }
/** Recover a base storage DatasetGraph */ public static void recovery(DatasetGraphTDB dsg) { if ( dsg.getLocation().isMem() ) return ; // Do we need to recover? Journal journal = findJournal(dsg) ; if ( journal == null || journal.isEmpty() ) return ; recoverFromJournal(dsg.getConfig(), journal) ; journal.close(); // Recovery complete. Tidy up. Node journal files have already been handled. if ( journal.getFilename() != null ) { if ( FileOps.exists(journal.getFilename()) ) FileOps.delete(journal.getFilename()) ; } }
@Override public void finishBulk() { loaderTriples.loadDataFinish() ; loaderQuads.loadDataFinish() ; loaderTriples.loadIndexStart() ; loaderQuads.loadIndexStart() ; loaderTriples.loadIndexFinish() ; loaderQuads.loadIndexFinish() ; loaderTriples.loadFinish() ; loaderQuads.loadFinish() ; if ( !dsg.getLocation().isMem() && startedEmpty && stats != null ) { String filename = dsg.getLocation().getPath(Names.optStats) ; Stats.write(filename, stats.results()) ; } forceSync(dsg) ; }