Commit 3bc99a61 authored by Vincent Pelletier's avatar Vincent Pelletier

Make it possible to disable compression for new stores.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2132 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 97f9a182
...@@ -34,10 +34,11 @@ class Storage(BaseStorage.BaseStorage, ...@@ -34,10 +34,11 @@ class Storage(BaseStorage.BaseStorage,
__name__ = 'NEOStorage' __name__ = 'NEOStorage'
def __init__(self, master_nodes, name, connector=None, read_only=False, def __init__(self, master_nodes, name, connector=None, read_only=False,
**kw): compress=True, **kw):
BaseStorage.BaseStorage.__init__(self, name) BaseStorage.BaseStorage.__init__(self, name)
self._is_read_only = read_only self._is_read_only = read_only
self.app = Application(master_nodes, name, connector) self.app = Application(master_nodes, name, connector,
compress=compress)
def load(self, oid, version=None): def load(self, oid, version=None):
try: try:
......
...@@ -122,7 +122,7 @@ class ThreadContext(object): ...@@ -122,7 +122,7 @@ class ThreadContext(object):
class Application(object): class Application(object):
"""The client node application.""" """The client node application."""
def __init__(self, master_nodes, name, connector=None, **kw): def __init__(self, master_nodes, name, connector=None, compress=True, **kw):
# Start polling thread # Start polling thread
self.em = EventManager() self.em = EventManager()
self.poll_thread = ThreadedPoll(self.em) self.poll_thread = ThreadedPoll(self.em)
...@@ -178,6 +178,7 @@ class Application(object): ...@@ -178,6 +178,7 @@ class Application(object):
lock = Lock() lock = Lock()
self._nm_acquire = lock.acquire self._nm_acquire = lock.acquire
self._nm_release = lock.release self._nm_release = lock.release
self.compress = compress
@profiler_decorator @profiler_decorator
def _handlePacket(self, conn, packet, handler=None): def _handlePacket(self, conn, packet, handler=None):
...@@ -572,12 +573,16 @@ class Application(object): ...@@ -572,12 +573,16 @@ class Application(object):
if data is None: if data is None:
# this is a George Bailey object, stored as an empty string # this is a George Bailey object, stored as an empty string
data = '' data = ''
compressed_data = compress(data) if self.compress:
if len(compressed_data) > len(data): compressed_data = compress(data)
if len(compressed_data) > len(data):
compressed_data = data
compression = 0
else:
compression = 1
else:
compressed_data = data compressed_data = data
compression = 0 compression = 0
else:
compression = 1
checksum = makeChecksum(compressed_data) checksum = makeChecksum(compressed_data)
p = Packets.AskStoreObject(oid, serial, compression, p = Packets.AskStoreObject(oid, serial, compression,
checksum, compressed_data, self.local_var.tid) checksum, compressed_data, self.local_var.tid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment