Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Don't allow reads inside a pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
rbranson committed Nov 29, 2012
1 parent 51ba637 commit dcb546c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ bool Client::flushAll(time_t *expiration, bool async)

m_writer.writeChars("\r\n", 2);

if (m_pipeline)
{
m_pipeline += 1;
return true;
}

if (!sendWriteBuffer())
{
return false;
Expand Down
30 changes: 30 additions & 0 deletions python/umemcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ PyObject *Client_get(PyClient *self, PyObject *args)
return NULL;
}

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

self->client->getBegin();

self->client->getKeyWrite(pKey, cbKey);
Expand Down Expand Up @@ -481,6 +486,11 @@ PyObject *Client_gets(PyClient *self, PyObject *args)
return NULL;
}

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

self->client->getsBegin();

self->client->getKeyWrite(pKey, cbKey);
Expand Down Expand Up @@ -541,6 +551,11 @@ PyObject *Client_get_multi(PyClient *self, PyObject *okeys)
UINT64 cas;
int flags;

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

self->client->getBegin();

PyObject *iterator = PyObject_GetIter(okeys);
Expand Down Expand Up @@ -622,6 +637,11 @@ PyObject *Client_gets_multi(PyClient *self, PyObject *okeys)
UINT64 cas;
int flags;

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

self->client->getsBegin();

PyObject *iterator = PyObject_GetIter(okeys);
Expand Down Expand Up @@ -922,6 +942,11 @@ PyObject *Client_version(PyClient *self, PyObject *args)
char *pVersion;
size_t cbVersion;

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

if (!self->client->version(&pVersion, &cbVersion))
{
return PyErr_Format(PyExc_RuntimeError, "Could not retrieve version");
Expand All @@ -937,6 +962,11 @@ PyObject *Client_stats(PyClient *self, PyObject *args)
size_t cbName;
size_t cbValue;

if (self->client->isPipelined())
{
return PyErr_Format(PyExc_RuntimeError, "Operation cannot be performed inside a pipeline");
}

if (!self->client->stats(NULL, 0))
{
return PyErr_Format(PyExc_RuntimeError, "Stats command failed");
Expand Down
24 changes: 24 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,30 @@ def testPipeline(self):
self.assertEquals("wilma", c1.get("cas2")[0])
self.assertEquals("fred", c1.get("cas3")[0])

# Flush All
c1.set("flush1", "foo")
c1.set("flush2", "bar")
c2.begin_pipeline()
c2.flush_all()
self.assertEquals("foo", c1.get("flush1")[0])
self.assertEquals("bar", c1.get("flush2")[0])
c2.finish_pipeline()
self.assertEquals(None, c1.get("flush1"))
self.assertEquals(None, c1.get("flush2"))


def testPipelineDoesNotAllowReads(self):
c = Client(MEMCACHED_ADDRESS)
c.connect()

c.begin_pipeline()

self.assertRaises(RuntimeError, c.get, "foo")
self.assertRaises(RuntimeError, c.gets, "foo")
self.assertRaises(RuntimeError, c.get_multi, ["foo"])
self.assertRaises(RuntimeError, c.gets_multi, ["foo"])
self.assertRaises(RuntimeError, c.version)
self.assertRaises(RuntimeError, c.stats)


if __name__ == '__main__':
Expand Down

0 comments on commit dcb546c

Please sign in to comment.