AsyncIterator `hasNext` method not returning value

I am using the FoundationDB Java API and am trying to get an AsyncIterator that will iterate through the whole database. The way I am currently doing it is as follows:

Transaction txn = this.db.createTransaction();
byte[] start = new byte[0];
byte[] end  = new byte[] {(byte) 0xFF};
AsyncIterable<KeyValue> iterable = txn.getRange(start, end);
AsyncIterator<KeyValue> iterator = iterable.iterator();

However, when I call iterator.hasNext(), I never get a value returned and since hasNext is a blocking call, I become stuck. Any ideas as to why this is happening and also whether or not this is the correct way to get an iterator for the whole database? I am aware that 0xFF in Java is -1 and that might be causing some issue?

Are you able to read a single key in your Java program using txn.get() (or even just get a read version using txn.getReadVersion())? One possible reason that hasNext could block is that you aren’t able to read from the database at all (e.g. due to the database being down or some sort of configuration error). If you can’t even do a single key read, then that may suggest your problem is of this nature instead. Another useful test in that case would be to see if you can perform reads on the cluster using fdbcli from the same host.

1 Like

Oh your hypothesis is correct. I ran fdbcli and ran the status command which outputted:

Could not communicate with a quorum of coordination servers:  (unreachable)

After doing some more searching, according to this post, I should start up the server by running ./bin/fdbserver. However, it seems like I do not have fdbserver at that location. Is there someplace I should go to install this or is it possible that it is located in a different path? The confusing thing to me is that I already installed the FoundationDB Client & Server Package for macOS which I assume should install fdbserver for me?

If you’ve installed the package, then it should both install and start fdbserver for you, unless you subsequently disabled it.

Can you grep your running processes for anything with fdb in it? The main thing we’d be looking for is fdbmonitor, which is the process that manages fdbserver and other processes. You could also look to see if there exists a running fdbserver and backup_agent process, which would normally be there by default.

If you don’t see fdbmonitor running at all, then we should try to fix that. You could verify that it exists on your system (I believe it should be located at /usr/local/libexec/fdbmonitor) and that it is configured to run in macOS.

If you see two instances of fdbmonitor running, then that would be an indication that fdbserver is failing to start properly (fdbmonitor spawns fdbserver by forking and execing, and errors can result in delays before the exec). Unfortunately on macOS we have an issue where the output from fdbmonitor doesn’t go anywhere, so if this is happening we won’t have a log for why. However, if this ends up being the problem we can manually set it up to get the logs.

One other thing you could do if you discover that you do have a running fdbserver process is to look in the fdbcli output for a warning message that the version of your fdbcli is incompatible with the cluster. Alternatively, you could run fdbcli -v and /path/to/running/fdbserver -v and confirm that the major and minor version numbers match (e.g. both are 6.2.x).

1 Like

I grep’ed my processes and found it! Turns out you were right. It doesn’t hang anymore, thanks for all the help!