# l = Logger("log")
# l.write(1,"w",0,5)
# l.write(2,"u",5,50)
# l.write(2,"u",3,90)
# l.write(3,"u",9,50)
# print("reading all the lines from newest to oldest")
# l.read()
# print("reading all the lines of thread id 2")
# print(l.read_tid(2))
db = Database()

grades_table = db.create_table('Grades', 5, 0)
#populate the table

q = Query(grades_table)
# print(inspect.getfullargspec(q.update))
t1 = Transaction()
t2 = Transaction()
t3 = Transaction()
t3.add_query(q.update, 1, *[6, 7, 8, 9, 10])
t1.add_query(q.insert, *[1, 2, 3, 4, 5])
t1.add_query(q.insert, *[0, 1, 2, 2, 5])
t2.add_query(q.insert, *[6, 7, 8, 9, 10])
t3.add_query(q.insert, *[6, 7, 8, 9, 10])
t3.add_query(q.insert, *[6, 7, 8, 9, 10])
txn_worker = TransactionWorker([t1, t2, t3])
th1 = threading.Thread(target=txn_worker.run)
th1.start()

# l = Logger("log")
    grades_table.index.create_index(1)
    grades_table.index.create_index(2)
    grades_table.index.create_index(3)
    grades_table.index.create_index(4)
except Exception as e:
    print('Index API not implemented properly, tests may fail.')

transaction_workers = []
insert_transactions = []
select_transactions = []
update_transactions = []
for i in range(num_threads):
    insert_transactions.append(Transaction())
    select_transactions.append(Transaction())
    update_transactions.append(Transaction())
    transaction_workers.append(TransactionWorker())
    transaction_workers[i].add_transaction(insert_transactions[i])
    #transaction_workers[i].add_transaction(select_transactions[i])
    #transaction_workers[i].add_transaction(update_transactions[i])
worker_keys = [ {} for t in transaction_workers ]

'''
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [key, randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20)]
    q = Query(grades_table)
    insert_transactions[i].add_query(q.insert, q.table, *records[key])
    worker_keys[i][key] = True
'''
Esempio n. 3
0
records = {}
num_threads = 4
seed(8739878934)

# Generate random records
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(*records[key])
    # print("keyToRID: ", q.table.keyToRID[key])
# create TransactionWorkers
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker(grades_table, i, quecc , []))
    #print(transaction_workers[i].result)

# generates 10k random transactions
# each transaction will increment the first column of a record 5 times
for i in range(1000):
    k = randint(0, 2000 - 1)
    transaction = Transaction()
    for j in range(5):
        key = keys[k * 5 + j]
        # print("key: ", key)
        q = Query(grades_table)
        transaction.add_query(q.select, key, 0, [1, 1, 1, 1, 1])
        q = Query(grades_table)
        transaction.add_query(q.increment, key, 1)
    transaction_workers[i % num_threads].add_transaction(transaction)