use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class DefaultIgfsSecondaryFileSystemTestAdapter method openOutputStream.
/**
* {@inheritDoc}
*/
@Override
public OutputStream openOutputStream(String path, boolean append) throws IOException {
IgfsPath igfsPath = new IgfsPath(path);
final IgfsOutputStream igfsOutputStream;
if (append)
igfsOutputStream = igfsEx.append(igfsPath, true);
else
igfsOutputStream = igfsEx.create(igfsPath, true);
return igfsOutputStream;
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractBaseSelfTest method appendFile.
/**
* Append to the file in the given IGFS provided data chunks.
*
* @param igfs IGFS.
* @param file File.
* @param chunks Data chunks.
* @throws Exception If failed.
*/
protected static void appendFile(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) throws Exception {
IgfsOutputStream os = null;
try {
os = igfs.append(file, false);
writeFileChunks(os, chunks);
} finally {
U.closeQuiet(os);
awaitFileClose(igfs, file);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendUpdateNoClose.
/**
* Test update on the file when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
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);
}
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendDeleteParentNoClose.
/**
* Test delete on the file parent when it was opened for write(append) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendDeleteParentNoClose() throws Exception {
if (mode != PRIMARY)
return;
if (appendSupported()) {
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, false);
IgfsOutputStream os = null;
IgniteUuid id = null;
try {
id = igfs.context().meta().fileId(FILE);
os = igfs.append(FILE, false);
// Since GG-4911 we allow deletes in this case.
boolean del = igfs.delete(SUBDIR, true);
assertTrue(del);
assertFalse(igfs.exists(FILE));
// id still exists in meta cache since
assertTrue(igfs.context().meta().exists(id));
// it is locked for writing and just moved to TRASH.
// Delete worker cannot delete it for that reason.
os.write(chunk);
os.close();
} finally {
U.closeQuiet(os);
}
assert id != null;
final IgniteUuid id0 = id;
// Delete worker should delete the file once its output stream is finally closed:
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return !igfs.context().meta().exists(id0);
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 5_000L);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testFormat.
/**
* Ensure that formatting is not propagated to the secondary file system.
*
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
public void testFormat() throws Exception {
if (mode == PROXY)
return;
final GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = getDataCache(igfs);
assert dataCache != null;
int size0 = dataCache.size(new CachePeekMode[] { CachePeekMode.ALL });
assert size0 == 0 : "Initial data cache size = " + size0;
if (dual)
create(igfsSecondary, paths(DIR, SUBDIR, DIR_NEW, SUBDIR_NEW), paths(FILE, FILE_NEW));
create(igfs, paths(DIR, SUBDIR), paths(FILE));
try (IgfsOutputStream os = igfs.create(FILE, true)) {
os.write(new byte[10 * 1024 * 1024]);
}
awaitFileClose(igfs, FILE);
if (dual)
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
checkExist(igfs, DIR, SUBDIR, FILE);
assertEquals(10 * 1024 * 1024, igfs.info(FILE).length());
assert dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) > 0;
igfs.clear();
// Ensure format is not propagated to the secondary file system.
if (dual) {
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
igfsSecondary.format();
}
// Ensure entries deletion in the primary file system.
checkNotExist(igfs, DIR, SUBDIR, FILE);
if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) == 0;
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 10_000)) {
Iterable<? extends GridCacheEntryEx> entries = dataCache.allEntries();
for (GridCacheEntryEx e : entries) {
X.println("deleted = " + e.deleted());
X.println("detached = " + e.detached());
X.println("info = " + e.info());
X.println("k = " + e.key() + ", v = " + e.valueBytes());
}
assert false;
}
}
Aggregations