use of water.Futures in project h2o-2 by h2oai.
the class CBSChunkTest method testImpl.
void testImpl(long[] ls, int[] xs, int expBpv, int expGap, int expClen, int expNA) {
AppendableVec av = new AppendableVec(Vec.newKey());
Futures fs = new Futures();
Vec vv = av.close(fs);
fs.blockForPending();
// Create a new chunk
NewChunk nc = new NewChunk(av, 0);
nc._ls = ls;
nc._xs = xs;
nc._len = nc._sparseLen = ls.length;
// Compute rollups, including NA
nc.type();
assertEquals(expNA, nc._naCnt);
// Compress chunk
Chunk cc = nc.compress();
assert cc instanceof CBSChunk;
cc._vec = av.close(fs);
fs.blockForPending();
assertTrue("Found chunk class " + cc.getClass() + " but expected " + CBSChunk.class, CBSChunk.class.isInstance(cc));
assertEquals(nc._len, cc._len);
assertEquals(expGap, ((CBSChunk) cc)._gap);
assertEquals(expBpv, ((CBSChunk) cc)._bpv);
assertEquals(expClen, cc._mem.length - CBSChunk.OFF);
// Also, we can decompress correctly
for (int i = 0; i < ls.length; i++) if (xs[i] == 0)
assertEquals(ls[i], cc.at80(i));
else
assertTrue(cc.isNA0(i));
UKV.remove(vv._key);
}
use of water.Futures in project h2o-3 by h2oai.
the class Session method assign.
/**
* Update a global ID, maintaining sharing of Vecs
*/
public Frame assign(Key<Frame> id, Frame src) {
if (FRAMES.containsKey(id))
throw new IllegalArgumentException("Cannot reassign temp " + id);
Futures fs = new Futures();
// Vec lifetime invariant: Globals do not share with other globals (but can
// share with temps). All the src Vecs are about to become globals. If
// the ID already exists, and global Vecs within it are about to die, and thus
// may be deleted.
Frame fr = DKV.getGet(id);
if (fr != null) {
// Prior frame exists
for (Vec vec : fr.vecs()) {
if (GLOBALS.remove(vec) && _getRefCnt(vec) == 0)
// Remove unused global vec
vec.remove(fs);
}
}
// Copy (defensive) the base vecs array. Then copy any vecs which are
// already globals - this new global must be independent of any other
// global Vecs - because global Vecs get side-effected by unrelated
// operations.
Vec[] svecs = src.vecs().clone();
for (int i = 0; i < svecs.length; i++) if (GLOBALS.contains(svecs[i]))
svecs[i] = svecs[i].makeCopy();
// Make and install new global Frame
Frame fr2 = new Frame(id, src._names.clone(), svecs);
DKV.put(fr2, fs);
addGlobals(fr2);
fs.blockForPending();
return fr2;
}
use of water.Futures in project h2o-3 by h2oai.
the class Session method endQuietly.
/**
* The Rapids call threw an exception. Best-effort cleanup, no more exceptions
*/
public RuntimeException endQuietly(Throwable ex) {
try {
GLOBALS.clear();
Futures fs = new Futures();
for (Frame fr : FRAMES.values()) {
for (Vec vec : fr.vecs()) {
Integer I = REFCNTS.get(vec);
int i = (I == null ? 0 : I) - 1;
if (i > 0)
REFCNTS.put(vec, i);
else {
REFCNTS.remove(vec);
vec.remove(fs);
}
}
// Shallow remove, internal Vecs removed 1-by-1
DKV.remove(fr._key, fs);
}
fs.blockForPending();
FRAMES.clear();
REFCNTS.clear();
} catch (Exception ex2) {
Log.warn("Exception " + ex2 + " suppressed while cleaning up Rapids Session after already throwing " + ex);
}
return ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex);
}
use of water.Futures in project h2o-3 by h2oai.
the class Session method remove.
/**
* Remove and delete a session-tracked frame.
* Remove from all session tracking spaces.
* Remove any newly-unshared Vecs, but keep the shared ones.
*/
public void remove(Frame fr) {
if (fr == null)
return;
Futures fs = new Futures();
if (!FRAMES.containsKey(fr._key)) {
// In globals and not temps?
for (Vec vec : fr.vecs()) {
// Not a global anymore
GLOBALS.remove(vec);
if (// If not shared with temps
REFCNTS.get(vec) == null)
// Remove unshared dead global
vec.remove(fs);
}
} else {
// Else a temp and not a global
// Standard down-ref counting of all Vecs
fs = downRefCnt(fr, fs);
// And remove from temps
FRAMES.remove(fr._key);
}
// Shallow remove, internal were Vecs removed 1-by-1
DKV.remove(fr._key, fs);
fs.blockForPending();
}
use of water.Futures in project h2o-3 by h2oai.
the class FVecParseWriter method close.
@Override
public FVecParseWriter close() {
Futures fs = new Futures();
close(fs);
fs.blockForPending();
return this;
}
Aggregations