From 07ac4037e58a5a6fb72d6d5ac075bf39f534716e Mon Sep 17 00:00:00 2001
From: Dmitry Simonenko <pmwkaa@gmail.com>
Date: Wed, 1 Apr 2015 13:08:44 +0400
Subject: [PATCH] expose sophia compression to tarantool

---
 src/box/lua/load_cfg.lua   |  6 ++++--
 src/box/sophia_index.cc    |  2 ++
 test/box/admin.result      |  3 ++-
 test/box/cfg.result        | 18 +++++++++---------
 test/sophia/options.result |  3 ++-
 third_party/sophia         |  2 +-
 6 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index be134f5138..55ee8e14fd 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -21,7 +21,8 @@ local default_sophia_cfg = {
     memory_limit = 0,
     threads      = 5,
     node_size    = 134217728,
-    page_size    = 131072
+    page_size    = 131072,
+    compression  = "none"
 }
 
 -- all available options
@@ -65,7 +66,8 @@ local sophia_template_cfg = {
     memory_limit = 'number',
     threads      = 'number',
     node_size    = 'number',
-    page_size    = 'number'
+    page_size    = 'number',
+    compression  = 'string'
 }
 
 -- types of available options
diff --git a/src/box/sophia_index.cc b/src/box/sophia_index.cc
index d81d2b6ca2..57c719b535 100644
--- a/src/box/sophia_index.cc
+++ b/src/box/sophia_index.cc
@@ -139,6 +139,8 @@ sophia_configure(struct space *space, struct key_def *key_def)
 	snprintf(pointer, sizeof(pointer), "pointer: %p", (void*)sophia_index_compare);
 	snprintf(pointer_arg, sizeof(pointer_arg), "pointer: %p", (void*)key_def);
 	sp_set(c, name, pointer, pointer_arg);
+	snprintf(name, sizeof(name), "db.%" PRIu32 ".compression", key_def->space_id);
+	sp_set(c, name, cfg_gets("sophia.compression"));
 	snprintf(name, sizeof(name), "db.%" PRIu32, key_def->space_id);
 	void *db = sp_get(c, name);
 	if (db == NULL)
diff --git a/test/box/admin.result b/test/box/admin.result
index 807cff8b1f..973347aa1b 100644
--- a/test/box/admin.result
+++ b/test/box/admin.result
@@ -26,9 +26,10 @@ box.cfg
   slab_alloc_arena: 0.1
   sophia:
     page_size: 131072
+    memory_limit: 0
     threads: 5
     node_size: 134217728
-    memory_limit: 0
+    compression: none
   listen: <uri>
   logger_nonblock: true
   snap_dir: .
diff --git a/test/box/cfg.result b/test/box/cfg.result
index 61e12fb73d..fc615be3ed 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -2,7 +2,7 @@
 --# push filter 'admin: .*' to 'admin: <uri>'
 box.cfg.nosuchoption = 1
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:260: Attempt to modify a read-only
+- error: '[string "-- load_cfg.lua - internal file..."]:262: Attempt to modify a read-only
     table'
 ...
 t = {} for k,v in pairs(box.cfg) do if type(v) ~= 'table' and type(v) ~= 'function' then table.insert(t, k..': '..tostring(v)) end end
@@ -36,7 +36,7 @@ t
 -- must be read-only
 box.cfg()
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:206: bad argument #1 to ''pairs''
+- error: '[string "-- load_cfg.lua - internal file..."]:208: bad argument #1 to ''pairs''
     (table expected, got nil)'
 ...
 t = {} for k,v in pairs(box.cfg) do if type(v) ~= 'table' and type(v) ~= 'function' then table.insert(t, k..': '..tostring(v)) end end
@@ -70,23 +70,23 @@ t
 -- check that cfg with unexpected parameter fails.
 box.cfg{sherlock = 'holmes'}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:162: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:164: Error: cfg parameter
     ''sherlock'' is unexpected'
 ...
 -- check that cfg with unexpected type of parameter failes
 box.cfg{listen = {}}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:182: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:184: Error: cfg parameter
     ''listen'' should be one of types: string, number'
 ...
 box.cfg{wal_dir = 0}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:176: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:178: Error: cfg parameter
     ''wal_dir'' should be of type string'
 ...
 box.cfg{coredump = 'true'}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:176: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:178: Error: cfg parameter
     ''coredump'' should be of type boolean'
 ...
 --------------------------------------------------------------------------------
@@ -94,17 +94,17 @@ box.cfg{coredump = 'true'}
 --------------------------------------------------------------------------------
 box.cfg{slab_alloc_arena = "100500"}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:176: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:178: Error: cfg parameter
     ''slab_alloc_arena'' should be of type number'
 ...
 box.cfg{sophia = "sophia"}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:170: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:172: Error: cfg parameter
     ''sophia'' should be a table'
 ...
 box.cfg{sophia = {threads = "threads"}}
 ---
-- error: '[string "-- load_cfg.lua - internal file..."]:176: Error: cfg parameter
+- error: '[string "-- load_cfg.lua - internal file..."]:178: Error: cfg parameter
     ''sophia.threads'' should be of type number'
 ...
 --------------------------------------------------------------------------------
diff --git a/test/sophia/options.result b/test/sophia/options.result
index 75c23ee4a8..4249fd3862 100644
--- a/test/sophia/options.result
+++ b/test/sophia/options.result
@@ -1,9 +1,10 @@
 box.cfg.sophia
 ---
 - page_size: 131072
+  memory_limit: 0
   threads: 0
   node_size: 134217728
-  memory_limit: 0
+  compression: none
 ...
 box.cfg.sophia.threads = 3
 ---
diff --git a/third_party/sophia b/third_party/sophia
index d7010473cf..68ce375fb7 160000
--- a/third_party/sophia
+++ b/third_party/sophia
@@ -1 +1 @@
-Subproject commit d7010473cfe8ceb7b1254183a77d286aa0cd3b11
+Subproject commit 68ce375fb75f9194edf967d96d0ff5dc04f3724f
-- 
GitLab