Created
March 2, 2021 01:20
-
-
Save kocolosk/6a4410b3ee8c6c06ed8d86deb6c76f19 to your computer and use it in GitHub Desktop.
Indexer can't make progress because of serializability conflicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import random | |
import requests | |
import threading | |
URL = 'http://127.0.0.1:15984/snapshots-for-indexing' | |
USER = 'adm' | |
PASS = 'pass' | |
#doc.foo | |
VIEW = { | |
"views" : { | |
"bar":{ | |
"map":"function (doc) { for (i=0; i<500; i++) { emit(i, [doc._rev, doc._local_seq]); } }" | |
} | |
}, | |
"options": {"local_seq": True} | |
} | |
BATCH_SIZE = 1 | |
def thread_fun(): | |
s = requests.Session() | |
s.auth = (USER, PASS) | |
name = threading.current_thread().name | |
docs = [ { '_id': '{}-{}'.format(name, i) } for i in range(BATCH_SIZE) ] | |
while True: | |
r = s.get('{}/{}-0'.format(URL, name)) | |
if r.status_code == 200: | |
rev = r.json()['_rev'] | |
for i in range(BATCH_SIZE): | |
docs[i]['_rev'] = rev | |
r2 = s.post('{}/_bulk_docs'.format(URL), json = {"docs": docs}) | |
if __name__ == "__main__": | |
s = requests.Session() | |
s.auth = (USER, PASS) | |
s.delete(URL) | |
s.put(URL) | |
s.put('{}/_design/foo'.format(URL), data = json.dumps(VIEW)) | |
random.seed(42) | |
for x in range(1): | |
t = threading.Thread(target=thread_fun) | |
t.start() | |
print("Writers started") | |
while True: | |
r = s.get('{}/_design/foo/_view/bar'.format(URL), params = {"limit": 1, "include_docs": True}) | |
j = r.json() | |
if j['total_rows'] == 0: | |
r2 = s.get(URL) | |
info = r2.json() | |
print("View is empty!! response time: {} doc_count: {} update_seq: {}".format(r.elapsed.total_seconds(), info['doc_count'], info['update_seq'])) | |
else: | |
rows = j['rows'] | |
print("View response status: {} row rev: {} doc rev: {} response time: {}".format(r.status_code, rows[0]['value'], rows[0]['doc']['_rev'], r.elapsed.total_seconds())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment