/** * Gets file ID for specified path. * * @param path Path. * @return File ID for specified path or {@code null} if such file doesn't exist. * @throws GridException If failed. */ @Nullable public GridUuid fileId(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileId(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping: " + path); }
/** * Gets file ID for specified path. * * @param path Path. * @return File ID for specified path or {@code null} if such file doesn't exist. * @throws GridException If failed. */ @Nullable public GridUuid fileId(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileId(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping: " + path); }
/** * Gets all file IDs for components of specified path. Result cannot be empty - there is at least root element. * But each element (except the first) can be {@code null} if such files don't exist. * * @param path Path. * @return Collection of file IDs for components of specified path. * @throws GridException If failed. */ public List<GridUuid> fileIds(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileIds(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file IDS because Grid is stopping: " + path); }
/** * Get sampling flag state. * * @return {@code True} in case sampling is enabled, {@code false} otherwise or {@code null} in case sampling * is not set. * @throws GridException If failed. */ public Boolean sampling() throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); Object val = metaCache.get(sampling); return (val == null || !(val instanceof Boolean)) ? null : (Boolean)val; } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get sampling flag because Grid is stopping."); }
/** * Get sampling flag state. * * @return {@code True} in case sampling is enabled, {@code false} otherwise or {@code null} in case sampling * is not set. * @throws GridException If failed. */ public Boolean sampling() throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); Object val = metaCache.get(sampling); return (val == null || !(val instanceof Boolean)) ? null : (Boolean)val; } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get sampling flag because Grid is stopping."); }
/** * Gets all file IDs for components of specified path. Result cannot be empty - there is at least root element. * But each element (except the first) can be {@code null} if such files don't exist. * * @param path Path. * @return Collection of file IDs for components of specified path. * @throws GridException If failed. */ public List<GridUuid> fileIds(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileIds(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file IDS because Grid is stopping: " + path); }
/** * Asynchronously updates record in parent listing. * * @param parentId Parent ID. * @param fileId File ID. * @param fileName File name. * @param lenDelta Length delta. * @param modificationTime Last modification time. */ public void updateParentListingAsync(GridUuid parentId, GridUuid fileId, String fileName, long lenDelta, long modificationTime) { if (busyLock.enterBusy()) { try { assert parentId != null; assert validTxState(false); id2InfoPrj.transformAsync(parentId, new UpdateListingEntry(fileId, fileName, lenDelta, 0, modificationTime)); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to update parent listing because Grid is stopping [parentId=" + parentId + ", fileId=" + fileId + ", fileName=" + fileName + ']'); }
if (busyLock.enterBusy()) { try { assert validTxState(false); assert fileIds != null;
if (busyLock.enterBusy()) { try { assert validTxState(false); assert fileIds != null;
/** * Lock file IDs participating in the transaction.<br/> * * @param fileIds file IDs to lock. * @return Locked file details. Resulting map doesn't contain details for not-existent files. * @throws GridException If failed. */ private Map<GridUuid, GridGgfsFileInfo> lockIds(GridUuid... fileIds) throws GridException { assert validTxState(true); assert fileIds != null && fileIds.length > 0; // Always sort file IDs participating in transaction to escape cache transaction deadlocks. Arrays.sort(fileIds); // Wrap array as collection (1) to escape superfluous check in projection and (2) to check assertions. Collection<GridUuid> keys = Arrays.asList(fileIds); if (log.isDebugEnabled()) log.debug("Locking file ids: " + keys); // Lock files and get their infos. Map<GridUuid, GridGgfsFileInfo> map = id2InfoPrj.getAll(keys); if (log.isDebugEnabled()) log.debug("Locked file ids: " + keys); // Force root ID always exist in cache. if (keys.contains(ROOT_ID) && !map.containsKey(ROOT_ID)) { GridGgfsFileInfo info = new GridGgfsFileInfo(); id2InfoPrj.putxIfAbsent(ROOT_ID, info); map = new GridLeanMap<>(map); map.put(ROOT_ID, info); } // Returns detail's map for locked IDs. return map; }
/** * Lock file IDs participating in the transaction.<br/> * * @param fileIds file IDs to lock. * @return Locked file details. Resulting map doesn't contain details for not-existent files. * @throws GridException If failed. */ private Map<GridUuid, GridGgfsFileInfo> lockIds(GridUuid... fileIds) throws GridException { assert validTxState(true); assert fileIds != null && fileIds.length > 0; // Always sort file IDs participating in transaction to escape cache transaction deadlocks. Arrays.sort(fileIds); // Wrap array as collection (1) to escape superfluous check in projection and (2) to check assertions. Collection<GridUuid> keys = Arrays.asList(fileIds); if (log.isDebugEnabled()) log.debug("Locking file ids: " + keys); // Lock files and get their infos. Map<GridUuid, GridGgfsFileInfo> map = id2InfoPrj.getAll(keys); if (log.isDebugEnabled()) log.debug("Locked file ids: " + keys); // Force root ID always exist in cache. if (keys.contains(ROOT_ID) && !map.containsKey(ROOT_ID)) { GridGgfsFileInfo info = new GridGgfsFileInfo(); id2InfoPrj.putxIfAbsent(ROOT_ID, info); map = new GridLeanMap<>(map); map.put(ROOT_ID, info); } // Returns detail's map for locked IDs. return map; }
if (busyLock.enterBusy()) { try { assert validTxState(false);
/** * Asynchronously updates record in parent listing. * * @param parentId Parent ID. * @param fileId File ID. * @param fileName File name. * @param lenDelta Length delta. * @param modificationTime Last modification time. */ public void updateParentListingAsync(GridUuid parentId, GridUuid fileId, String fileName, long lenDelta, long modificationTime) { if (busyLock.enterBusy()) { try { assert parentId != null; assert validTxState(false); id2InfoPrj.transformAsync(parentId, new UpdateListingEntry(fileId, fileName, lenDelta, 0, modificationTime)); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to update parent listing because Grid is stopping [parentId=" + parentId + ", fileId=" + fileId + ", fileName=" + fileName + ']'); }
/** * Update cached value with closure. * * @param cache Cache projection to work with. * @param key Key to retrieve/update the value for. * @param c Closure to apply to cached value. * @return {@code True} if value was stored in cache, {@code false} otherwise. * @throws GridException If operation failed. */ private <K, V> boolean putx(GridCacheProjection<K, V> cache, K key, GridClosure<V, V> c) throws GridException { assert validTxState(true); V oldVal = cache.get(key); V newVal = c.apply(oldVal); return newVal == null ? cache.removex(key) : cache.putx(key, newVal); }
/** * Update cached value with closure. * * @param cache Cache projection to work with. * @param key Key to retrieve/update the value for. * @param c Closure to apply to cached value. * @return {@code True} if value was stored in cache, {@code false} otherwise. * @throws GridException If operation failed. */ private <K, V> boolean putx(GridCacheProjection<K, V> cache, K key, GridClosure<V, V> c) throws GridException { assert validTxState(true); V oldVal = cache.get(key); V newVal = c.apply(oldVal); return newVal == null ? cache.removex(key) : cache.putx(key, newVal); }
if (busyLock.enterBusy()) { try { assert validTxState(false);
if (busyLock.enterBusy()) { try { assert validTxState(false); assert parentId != null; assert fileName != null;
newFileInfo + ']'); validTxState(true); assert validTxState(true); assert validTxState(true);
/** * Set sampling flag. * * @param val Sampling flag state or {@code null} to clear sampling state and mark it as "not set". * @return {@code True} if sampling mode was actually changed by this call. * @throws GridException If failed. */ public boolean sampling(Boolean val) throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); try { Object prev = val != null ? metaCache.put(sampling, val) : metaCache.remove(sampling); tx.commit(); return !F.eq(prev, val); } finally { tx.close(); } } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to set sampling flag because Grid is stopping."); }
/** * Set sampling flag. * * @param val Sampling flag state or {@code null} to clear sampling state and mark it as "not set". * @return {@code True} if sampling mode was actually changed by this call. * @throws GridException If failed. */ public boolean sampling(Boolean val) throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); try { Object prev = val != null ? metaCache.put(sampling, val) : metaCache.remove(sampling); tx.commit(); return !F.eq(prev, val); } finally { tx.close(); } } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to set sampling flag because Grid is stopping."); }