Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

active shards 1 crate #384

Merged
merged 4 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/manuals/admin/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ To configure QuantumLeap you can use the following environment variables:
| `DEFAULT_CACHE_TTL`| Time to live of metadata cache, default: 60 (seconds) | |
| `QL_CONFIG` | Pathname for tenant configuration |
| `QL_DEFAULT_DB` | Default backend: `timescale` or `crate` |
| `CRATE_WAIT_ACTIVE_SHARDS` | Specifies the number of shard copies that need to be active for write operations to proceed. Default `1`. See related [crate documentation](https://crate.io/docs/crate/reference/en/4.3/sql/statements/create-table.html#write-wait-for-active-shards). |
| `USE_FLASK` | `True` or `False` to use flask server (only for Dev) or gunicorn. Default to `False` |
| `LOGLEVEL` | Define the log level for all services (`DEBUG`, `INFO`, `WARNING` , `ERROR`) |

Expand Down
12 changes: 9 additions & 3 deletions src/translators/crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def setup(self):
# we need to think if we want to cache this information
# and save few msec for evey API call
self.db_version = self.get_db_version()
self.active_shards = EnvReader(log=logging.getLogger(__name__).debug)\
.read(StrVar('CRATE_WAIT_ACTIVE_SHARDS', '1'))

major = int(self.db_version.split('.')[0])
if major <= 2:
Expand Down Expand Up @@ -170,8 +172,10 @@ def _create_data_table(self, table_name, table, fiware_service):
columns = ', '.join('"{}" {}'.format(cn.lower(), ct)
for cn, ct in table.items())
stmt = "create table if not exists {} ({}) with " \
"(number_of_replicas = '2-all', " \
"column_policy = 'strict')".format(table_name, columns)
"(\"number_of_replicas\" = '2-all', " \
"\"column_policy\" = 'strict', " \
"\"write.wait_for_active_shards\" = '{}'" \
")".format(table_name, columns, self.active_shards)
self.cursor.execute(stmt)

def _update_data_table(self, table_name, new_columns, fiware_service):
Expand All @@ -188,7 +192,9 @@ def _should_insert_original_entities(self,
def _create_metadata_table(self):
stmt = "create table if not exists {} " \
"(table_name string primary key, entity_attrs object) " \
"with (number_of_replicas = '2-all', column_policy = 'dynamic')"
"with (" \
"number_of_replicas = '2-all', " \
"column_policy = 'dynamic')"
op = stmt.format(METADATA_TABLE_NAME)
self.cursor.execute(op)

Expand Down