/** * Append some data to the given file. * * @param path File path. * @param len Data length. * @throws Exception If failed. */ private void append(IgfsPath path, int len) throws Exception { IgfsOutputStream os = igfsPrimary.append(path, false); os.write(new byte[len]); os.close(); }
/** * Write data to the file. * * @param chunks Data chunks. * @throws Exception In case of exception. */ protected void write(byte[]... chunks) throws Exception { IgfsOutputStream os = igfs.create(FILE, true); if (chunks != null) { for (byte[] chunk : chunks) os.write(chunk); } os.close(); }
@SuppressWarnings("ThrowFromFinallyBlock") @Override public void run() { while (!stop.get() && err.get() == null) { IgfsOutputStream os = null; try { os = igfs.append(FILE, false); os.write(chunk); os.close(); chunksCtr.incrementAndGet(); } catch (IgniteException ignore) { // No-op. } catch (IOException e) { err.compareAndSet(null, e); } finally { if (os != null) try { os.close(); } catch (IOException ioe) { throw new IgniteException(ioe); } } } } }, threadCnt);
@Override public Object call() throws Exception { IgfsOutputStream osErr = igfs(0).append(path, false); try { for (int i = 0; i < maxSize / writeChunkSize * GRID_CNT; ++i) osErr.write(chunk(writeChunkSize)); osErr.close(); return null; } catch (IOException e) { Throwable e0 = e; while (e0.getCause() != null) e0 = e0.getCause(); throw (Exception)e0; } finally { U.closeQuiet(osErr); } } }, IgniteOutOfMemoryException.class, "Not enough memory allocated");
/** {@inheritDoc} */ @Override public void handleFile(String strPath) throws Exception { IgfsPath path = new IgfsPath(strPath); IgfsOutputStream out; try { out = fs.create(path, false); } catch (IgniteException ex) { System.out.println("create file " + path.toString() + " failed: " + ex); throw ex; } try { for (int i = 0; i < size / dataBufer.capacity(); i++) out.write(dataBufer.array()); } catch (IOException ex) { System.out.println("write file " + path.toString() + " failed: " + ex); throw ex; } finally { out.close(); } }
@Override public void run() { int idx = ctr.incrementAndGet(); final IgfsPath path = new IgfsPath("/file" + idx); try { for (int i = 0; i < REPEAT_CNT; i++) { IgfsOutputStream os = igfs.create(path, 128, true/*overwrite*/, null, 0, 256, null); os.write(chunk); os.close(); assert igfs.exists(path); } awaitFileClose(igfs, path); checkFileContent(igfs, path, chunk); } catch (IOException | IgniteCheckedException e) { err.compareAndSet(null, e); // Log the very first error. } } }, threadCnt);
@Override public void run() { int idx = ctr.getAndIncrement(); IgfsPath path = new IgfsPath("/file" + idx); try { byte[][] chunks = new byte[REPEAT_CNT][]; for (int i = 0; i < REPEAT_CNT; i++) { chunks[i] = chunk; IgfsOutputStream os = igfs.append(path, false); os.write(chunk); os.close(); assert igfs.exists(path); } awaitFileClose(igfs, path); checkFileContent(igfs, path, chunks); } catch (IOException | IgniteCheckedException e) { err.compareAndSet(null, e); // Log the very first error. } } }, threadCnt);
/** @throws Exception If failed. */ @Test public void testMultipleClose() throws Exception { IgniteFileSystem fs = igfsPrimary[0]; IgfsOutputStream out = fs.create(new IgfsPath("/primary/file"), false); out.close(); out.close(); IgfsInputStream in = fs.open(new IgfsPath("/primary/file")); in.close(); in.close(); IgfsMetrics m = fs.metrics(); assertEquals(0, m.filesOpenedForWrite()); assertEquals(0, m.filesOpenedForRead()); }
/** * Test rename on the file when it was opened for write(create) and is not closed yet. * * @throws Exception If failed. */ @Test public void testCreateRenameNoClose() throws Exception { if (dual) return; create(igfs, paths(DIR, SUBDIR), null); IgfsOutputStream os = null; try { os = igfs.create(FILE, true); igfs.rename(FILE, FILE2); os.close(); } finally { U.closeQuiet(os); } }
/** * Test rename on the file parent when it was opened for write(create) and is not closed yet. * * @throws Exception If failed. */ @Test public void testCreateRenameParentNoClose() throws Exception { if (dual) return; create(igfs, paths(DIR, SUBDIR), null); IgfsOutputStream os = null; try { os = igfs.create(FILE, true); igfs.rename(SUBDIR, SUBDIR2); os.close(); } finally { U.closeQuiet(os); } }
/** * Checks simple write. * * @throws Exception On error. */ @Test public void testSimpleWrite() throws Exception { IgfsPath path = new IgfsPath("/file1"); IgfsOutputStream os = igfs.create(path, 128, true/*overwrite*/, null, 0, 256, null); os.write(chunk); os.close(); assert igfs.exists(path); checkFileContent(igfs, path, chunk); os = igfs.create(path, 128, true/*overwrite*/, null, 0, 256, null); assert igfs.exists(path); os.write(chunk); assert igfs.exists(path); os.write(chunk); assert igfs.exists(path); os.close(); assert igfs.exists(path); checkFileContent(igfs, path, chunk, chunk); }
/** * Ensure that a DUAL mode file is not propagated to eviction policy * * @throws Exception If failed. */ @Test public void testFileDualExclusion() throws Exception { start(); evictPlc.setExcludePaths(Collections.singleton(FILE_RMT.toString())); // Create file in primary mode. It must not be propagated to eviction policy. igfsPrimary.create(FILE_RMT, true).close(); checkEvictionPolicy(0, 0); int blockSize = igfsPrimary.info(FILE_RMT).blockSize(); append(FILE_RMT, blockSize); checkEvictionPolicy(0, 0); read(FILE_RMT, 0, blockSize); checkEvictionPolicy(0, 0); }
/** * Test rename on the file when it was opened for write(append) and is not closed yet. * * @throws Exception If failed. */ @Test public void testAppendRenameNoClose() throws Exception { if (dual) return; if (appendSupported()) { create(igfs, paths(DIR, SUBDIR), null); createFile(igfs, FILE, false); IgfsOutputStream os = null; try { os = igfs.append(FILE, false); igfs.rename(FILE, FILE2); os.close(); } finally { U.closeQuiet(os); } } }
/** * Test rename on the file parent when it was opened for write(append) and is not closed yet. * * @throws Exception If failed. */ @Test public void testAppendRenameParentNoClose() throws Exception { if (dual) return; if (appendSupported()) { create(igfs, paths(DIR, SUBDIR), null); createFile(igfs, FILE, false); IgfsOutputStream os = null; try { os = igfs.append(FILE, false); igfs.rename(SUBDIR, SUBDIR2); os.close(); } finally { U.closeQuiet(os); } } }
/** * Test update on the file when it was opened for write(create) and is not closed yet. * * @throws Exception If failed. */ @Test public void testCreateUpdateNoClose() throws Exception { if (dual) return; if(!propertiesSupported()) return; Map<String, String> props = properties("owner", "group", "0555"); create(igfs, paths(DIR, SUBDIR), null); IgfsOutputStream os = null; try { os = igfs.create(FILE, true); igfs.update(FILE, props); os.close(); } finally { U.closeQuiet(os); } }
/** * Test how evictions are handled for a file working in PRIMARY mode. * * @throws Exception If failed. */ @Test public void testFilePrimary() throws Exception { start(); // Create file in primary mode. It must not be propagated to eviction policy. igfsPrimary.create(FILE, true).close(); checkEvictionPolicy(0, 0); int blockSize = igfsPrimary.info(FILE).blockSize(); append(FILE, blockSize); checkEvictionPolicy(0, 0); read(FILE, 0, blockSize); checkEvictionPolicy(0, 0); }
/** * Test update on the file when it was opened for write(create) and is not closed yet. * * @throws Exception If failed. */ @Test public void testAppendUpdateNoClose() throws Exception { if (dual) return; if (appendSupported()) { Map<String, String> props = properties("owner", "group", "0555"); create(igfs, paths(DIR, SUBDIR), null); createFile(igfs, FILE, false); IgfsOutputStream os = null; try { os = igfs.append(FILE, false); if (permissionsSupported()) igfs.update(FILE, props); os.close(); } finally { U.closeQuiet(os); } } }
/** * Test how evictions are handled for a file working in PRIMARY mode. * * @throws Exception If failed. */ @Test public void testFileDual() throws Exception { start(); igfsPrimary.create(FILE_RMT, true).close(); checkEvictionPolicy(0, 0); int blockSize = igfsPrimary.info(FILE_RMT).blockSize(); // File write. append(FILE_RMT, blockSize); checkEvictionPolicy(1, blockSize); // One more write. append(FILE_RMT, blockSize); checkEvictionPolicy(2, blockSize * 2); // Read. read(FILE_RMT, 0, blockSize); checkEvictionPolicy(2, blockSize * 2); }
/** * Test eviction caused by too much blocks. * * @throws Exception If failed. */ @Test public void testBlockCountEviction() throws Exception { start(); int blockCnt = 3; evictPlc.setMaxBlocks(blockCnt); igfsPrimary.create(FILE_RMT, true).close(); checkEvictionPolicy(0, 0); int blockSize = igfsPrimary.info(FILE_RMT).blockSize(); // Write blocks up to the limit. append(FILE_RMT, blockSize * blockCnt); checkEvictionPolicy(blockCnt, blockCnt * blockSize); // Write one more block what should cause eviction. append(FILE_RMT, blockSize); checkEvictionPolicy(blockCnt, blockCnt * blockSize); // Read the first block. read(FILE_RMT, 0, blockSize); checkEvictionPolicy(blockCnt, blockCnt * blockSize); checkMetrics(1, 1); }