Skip to content

Twisted backend for Python driver (#3785) - #4096

Merged
Tryneus merged 1 commit into
rethinkdb:nextfrom
RaitoBezarius:next
Jul 21, 2015
Merged

Tryneus merged 1 commit into
rethinkdb:nextfrom
RaitoBezarius:next

Conversation

@RaitoBezarius

Copy link
Copy Markdown
Contributor

As discussed in #3785, here is my PR for the Twisted backend.
It has been tested (on a small part). Tests have been added (RaitoBezarius@2a8bac5), but I can't test yet (don't have the environnement for).

Keep the great work going, guys!

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

Added tests in RaitoBezarius@2a8bac5
But unsure if they'll really work.

@danielmewes

Copy link
Copy Markdown
Member

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

What's up about this pull request, it has been nearly 2 months on hold?

@danielmewes

Copy link
Copy Markdown
Member

Sorry for the delay @RaitoBezarius. We really appreciate your contribution and patience.

We've had a very busy time working on a complete rewrite of RethinkDB's clustering internals (which includes auto failover, better availability, improved cluster management among others).

We'll try to get to your pull request asap.

Comment thread drivers/python/rethinkdb/net_twisted.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this will work if the driver receives two responses in a single dataReceived callback. It should save the remainder of the buffer (same goes for _handleHandshake, though it's not likely someone will be sending queries before the handshake response is received).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, I'll do it as soon as possible!

@Tryneus

Tryneus commented Jun 23, 2015

Copy link
Copy Markdown
Member

Ok, @RaitoBezarius, I've taken a look and commented on a few things that looked off. Primarily, though, the tests won't run, so I can't do any manual verification (especially useful because I'm new to Twisted). Sorry about the delay in getting to this, but please take a look and let me know your thoughts.

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

Thanks, @Tryneus! I'll take the time to look about it and make the modifications.
Is there any information on how to run tests?

@Tryneus

Tryneus commented Jun 23, 2015

Copy link
Copy Markdown
Member

@RaitoBezarius: first you need to build the server (see instructions here. Once that is done, you should go to the test/rql_test/ directory and run ./test-runner -i py connections/twisted_connection --verbose. Let me know if you have any trouble getting these steps to work.

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

@Tryneus : [FIXED EDIT] I have a strange permission error when running tests:

Failed starting testTraceback (most recent call last):
  File "./test-runner", line 1436, in run
    test.startTest(server=self.server)
  File "./test-runner", line 1016, in startTest
    self.testProcess = subprocess.Popen(self.command, stdout=self.__console_output, stderr=self.__console_output, preexec_fn=os.setpgrp, env=envVariables)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied

When I printed the command, I got /home/raitobezarius/some_path/twisted_connections.py.test
I don't understand why I don't have permission (I even tried with sudo, it didn't work ! :D)

Here is a full Gist of what the runner printed: https://gist.github.com/RaitoBezarius/22b876a95ad90e9c1e37

I've run tests manually with python twisted_connections.py.test
But the test output seems broken, I can't read what is OK and what is not.

EDIT: Nevermind, I had to set executable bit on twisted_connection.py*
Sorry !

@Tryneus

Tryneus commented Jun 24, 2015

Copy link
Copy Markdown
Member

@RaitoBezarius, glad you got the permissions working, I noticed they were wrong when I was trying to get the tests running, but didn't think to mention it.

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

@Tryneus I've finally succeeded to make tests works, and then, I've discovered that a lot of the Cursor API is broken and does not work as expected.
I have one question about how cursor works.
For example, this test:

    @asyncio.coroutine
    def test_cursor_after_cursor_close(self):
        cursor = yield from r.range().run(self.conn)
        cursor.close()
        count = 0
        while (yield from cursor.fetch_next()):
            yield from cursor.next()
            count += 1
        self.assertNotEqual(count, 0, "Did not get any cursor results")

If I understand correctly, it means that a cursor fetch immediately when it is instantiated some data.
I have some issues to visualize mentally how this data fetching happen and where?

EDIT: I've answered many of your line notes, please take a look and let me know if I've forgotten something!

@Tryneus

Tryneus commented Jun 24, 2015

Copy link
Copy Markdown
Member

@RaitoBezarius, when a query response arrives, it can indicate that it is just the first batch of a larger result - this is when we create a Cursor object. The Cursor is instantiated with the original batch of data, but will request more immediately (pre-fetching) to reduce latency. Since the first batch of a normal cursor contains data (changefeeds are different - they may or may not have data in the first batch) - this test makes sure that the cursor will return the data it has already received from the server before stopping due to the close.

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

@Tryneus: If it can help you with Twisted, you can play around with the driver.
Type in a terminal: python -m twisted.conch.stdio and you will get a magic REPL!
You can import rethinkdb. Set the Twisted loop type. A reactor will be automagically run and all Deferred will be resolved / errback-ed effortlessly.

It can help you to test the driver in a REPL (which is quite cool).

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

@Tryneus: Finished! As you can see, I've made all the modifications in order to make tests pass.
Let me know if I've missed something or I need to check another thing!

Comment thread drivers/python/rethinkdb/net_twisted.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't fail until all successful rows have been read out from the cursor - that is, when len(self.items) == 0. Only once all the items have been read should we throw the error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, it is fixed in the last commit !

@Tryneus

Tryneus commented Jul 6, 2015

Copy link
Copy Markdown
Member

@RaitoBezarius, thanks for taking a look at it - I ran into several things when testing it on my local machine, so I opened a pull request on your fork with my fixes/suggestions. Please take a look and we can combine it into this PR later.

Fix for Twisted driver Python 3 compatibility and some corner cases
@Tryneus
Tryneus merged commit fe73cb7 into rethinkdb:next Jul 21, 2015
@Tryneus

Tryneus commented Jul 21, 2015

Copy link
Copy Markdown
Member

Finally got back to this, ran some tests and everything seems to be working fine. Merged to next as of commit 2d62bbb, and to v2.1.x in commit b5d5e5e, will be in release 2.1.0. Thanks for all the help, @RaitoBezarius!

@RaitoBezarius

Copy link
Copy Markdown
Contributor Author

Thanks to you too @Tryneus ! :)

@danielmewes

Copy link
Copy Markdown
Member

👏 another backend :-)
Thanks @RaitoBezarius and @Tryneus .

@danielmewes danielmewes added this to the 2.1 milestone Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants