Skip to content
Permalink
Browse files

Propagate cache reading failures (#2062)

- ClosingTest had to be updated, as it tries to read an empty file and is actually a failure
  • Loading branch information...
jackgerrits committed Aug 30, 2019
1 parent eb6be87 commit a4ff3d55fabac70b690664676cbe91f42f0f305b
Showing with 22 additions and 35 deletions.
  1. +2 −5 java/src/test/java/vowpalWabbit/ClosingTest.java
  2. +20 −30 vowpalwabbit/parser.cc
@@ -172,17 +172,14 @@ private VWScalarLearner model(final int passes) throws IOException {
}

private VWScalarLearner model(final int passes, final boolean quiet) throws IOException {
File cacheFile = File.createTempFile("ClosingTest", ".vw.cache");
cacheFile.deleteOnExit();

String command =
(!DIAGNOSTICS && quiet ?
" --quiet " :
" --progress " + ((int) Math.round(passes / 10d))
) +
) +
" --passes " + passes +
" --holdout_off " +
" --cache_file " + cacheFile.getCanonicalPath();
" --cache";

// Create a learner and just have it take 1 example, but many passes.
VWScalarLearner vw = VWLearners.create(command);
@@ -89,39 +89,29 @@ void set_compressed(parser* par)

uint32_t cache_numbits(io_buf* buf, int filepointer)
{
try
size_t v_length;
buf->read_file(filepointer, (char*)&v_length, sizeof(v_length));
if (v_length > 61)
THROW("cache version too long, cache file is probably invalid");

if (v_length == 0)
THROW("cache version too short, cache file is probably invalid");

std::vector<char> t(v_length);
buf->read_file(filepointer, t.data(), v_length);
VW::version_struct v_tmp(t.data());
if (v_tmp != VW::version)
{
size_t v_length;
buf->read_file(filepointer, (char*)&v_length, sizeof(v_length));
if (v_length > 61)
THROW("cache version too long, cache file is probably invalid");

if (v_length == 0)
THROW("cache version too short, cache file is probably invalid");

std::vector<char> t(v_length);
buf->read_file(filepointer, t.data(), v_length);
VW::version_struct v_tmp(t.data());
if (v_tmp != VW::version)
{
// cout << "cache has possibly incompatible version, rebuilding" << endl;
return 0;
}
// cout << "cache has possibly incompatible version, rebuilding" << endl;
return 0;
}

char temp;
if (buf->read_file(filepointer, &temp, 1) < 1)
THROW("failed to read");
char temp;
if (buf->read_file(filepointer, &temp, 1) < 1)
THROW("failed to read");

if (temp != 'c')
THROW("data file is not a cache file");
}
catch (...)
{
// TODO fix this exception bubbling behavior: https://github.com/VowpalWabbit/vowpal_wabbit/issues/1774
// Prior to using a std::vector, a v_array was used and the catch statement was used to delete it.
// This caused any exception to be ignored. Bubbling up this exception causes tests to fail so
// I am going to swallow it to maintain previous behavior.
}
if (temp != 'c')
THROW("data file is not a cache file");

uint32_t cache_numbits;
if (buf->read_file(filepointer, &cache_numbits, sizeof(cache_numbits)) < (int)sizeof(cache_numbits))

0 comments on commit a4ff3d5

Please sign in to comment.
You can’t perform that action at this time.