Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for #379, save() ignores write failures #380

Merged
merged 3 commits into from
Apr 8, 2019

Conversation

keithmcneill
Copy link
Contributor

No description provided.

@keithmcneill keithmcneill requested review from psobot and erikbern April 8, 2019 16:59
@@ -878,11 +880,25 @@ template<typename S, typename T, typename Distance, typename Random>
if (f == NULL)
return false;

fwrite(_nodes, _s, _n_nodes, f);
fclose(f);
bool write_failed = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this one is really needed, could just return false at each point?

not blocking though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored that a few times deciding if I wanted to unload or not in case of error. That is a vestige of that.

@erikbern erikbern merged commit 31015fd into spotify:master Apr 8, 2019
@erikbern
Copy link
Collaborator

erikbern commented Apr 8, 2019

thanks!

Copy link
Member

@psobot psobot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but left a couple comments.

t.add_item(i, v)
t.build(10)

if sys.platform == "linux" or sys.platform == "linux2":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.save("/dev/full")
self.fail("didn't get expected exception")
except Exception as e:
self.assertTrue(str(e).find("No space left on device") > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python nit: could do self.assertTrue("No space left on device" in str(e)) or in newer versions, self.assertIn("No space left on device", str(e))

t.save('/Volumes/%s/annoy.tree' % volume)
self.fail("didn't get expected exception")
except Exception as e:
self.assertTrue(str(e).find("No space left on device") > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

elif sys.platform == "darwin":
volume = "FULLDISK"
device = os.popen('hdiutil attach -nomount ram://64').read()
os.popen('diskutil erasevolume MS-DOS %s %s' % (volume, device))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but I'm pretty wary of calling diskutil erasevolume from a unit test. Is there a simpler way we can cause an error? (Maybe writing to a special file, like a named pipe or socket instead?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure a pipe would work. Might just block rather than out of disk space. I agree it is a bit wonky. Possibly we just test this on linux? Where it is clear and concise?

@psobot
Copy link
Member

psobot commented Apr 8, 2019

Great timing @erikbern! 😂

@keithmcneill
Copy link
Contributor Author

@erikbern When do you expect you're going to push out a new version? This fix is a for a production incident I'd like to get sorted out. Thanks!

@erikbern
Copy link
Collaborator

erikbern commented Apr 9, 2019

I can do that later tonight, but please remind me if I forget!

@erikbern
Copy link
Collaborator

The test doesn't seem to be working on OS X:

touch: /Volumes/FULLDISK/full: No such file or directory
F
======================================================================
FAIL: test_write_failed (index_test.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/erikbern/annoy/test/index_test.py", line 199, in test_write_failed
    t.save('/Volumes/%s/annoy.tree' % volume)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/erikbern/annoy/test/index_test.py", line 202, in test_write_failed
    self.assertTrue(str(e).find("No space left on device") > 0)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 1 test in 1.370s

@keithmcneill
Copy link
Contributor Author

Interesting, I wonder if one of the previous steps failed, and then didn't actually create the volume.

Given that there is the linux test, I think you can just delete the mac test.

@erikbern
Copy link
Collaborator

ok, will just delete it

@keithmcneill
Copy link
Contributor Author

@erikbern Any chance of getting out a new version this week so I can update our internals here?

Keith

@erikbern
Copy link
Collaborator

sure can do tonight

@erikbern
Copy link
Collaborator

done

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants