Software /
code /
prosody
Comparison
core/storagemanager.lua @ 7150:fcaaafe4062f
storagemanager: When map store isn't available, fallback to keyval store [backported from trunk]
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Thu, 07 Aug 2014 12:15:15 -0400 |
parent | 6951:99de8f30d99e |
child | 7151:584d5229cb91 |
comparison
equal
deleted
inserted
replaced
7149:bb0fd02ae70f | 7150:fcaaafe4062f |
---|---|
97 driver = null_storage_driver; | 97 driver = null_storage_driver; |
98 end | 98 end |
99 return driver, driver_name; | 99 return driver, driver_name; |
100 end | 100 end |
101 | 101 |
102 local function open(host, store, typ) | 102 local map_shim_mt = { |
103 __index = { | |
104 get = function(self, username, key) | |
105 local ret, err = self.keyval_store:get(username); | |
106 if ret == nil and err then return nil, err end | |
107 return ret[key]; | |
108 end; | |
109 set = function(self, username, key, data) | |
110 local current, err = self.keyval_store:get(username); | |
111 if current == nil then | |
112 if err then | |
113 return nil, err; | |
114 else | |
115 current = {}; | |
116 end | |
117 end | |
118 current[key] = data; | |
119 return self.keyval_store:set(username, current); | |
120 end; | |
121 }; | |
122 } | |
123 | |
124 local open; | |
125 | |
126 local function create_map_shim(host, store) | |
127 local keyval_store, err = open(host, store, "keyval"); | |
128 if keyval_store == nil then return nil, err end | |
129 return setmetatable({ | |
130 keyval_store = keyval_store; | |
131 }, map_shim_mt); | |
132 end | |
133 | |
134 function open(host, store, typ) | |
103 local driver, driver_name = get_driver(host, store); | 135 local driver, driver_name = get_driver(host, store); |
104 local ret, err = driver:open(store, typ); | 136 local ret, err = driver:open(store, typ); |
105 if not ret then | 137 if not ret then |
106 if err == "unsupported-store" then | 138 if err == "unsupported-store" then |
139 if typ == "map" then -- Use shim on top of keyval store | |
140 log("debug", "map storage driver unavailable, using shim on top of keyval store."); | |
141 return create_map_shim(host, store); | |
142 end | |
107 log("debug", "Storage driver %s does not support store %s (%s), falling back to null driver", | 143 log("debug", "Storage driver %s does not support store %s (%s), falling back to null driver", |
108 driver_name, store, typ or "<nil>"); | 144 driver_name, store, typ or "<nil>"); |
109 ret = null_storage_driver; | 145 ret = null_storage_driver; |
110 err = nil; | 146 err = nil; |
111 end | 147 end |