Changeset: 08dc62ab8131 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=08dc62ab8131
Added Files:
manipulate_monet.py
Modified Files:
monetdb5/optimizer/opt_hitchhiker.c
sql/backends/monet5/sql.mal
sql/backends/monet5/sql_hitchhiker.c
Branch: hitchhiker
Log Message:
landscape arguments - manipulate monetdb
diffs (206 lines):
diff --git a/manipulate_monet.py b/manipulate_monet.py
new file mode 100644
--- /dev/null
+++ b/manipulate_monet.py
@@ -0,0 +1,78 @@
+from pymonetdb import mapi
+import subprocess
+import sys
+import os
+
+available_cases = [ "start", "stop", "cleanup", "create_tables", "execute" ]
+all_servers = [ 50000, 50001, 50002 ]
+all_db_paths = [ "/tmp/mdb1", "/tmp/mdb2", "/tmp/mdb3" ]
+hostname = "localhost"
+username = "monetdb"
+password = "monetdb"
+
+if len(sys.argv) < 2:
+ print("Usage: python <script.py> <start | stop | cleanup | execute>")
+ sys.exit()
+else:
+ monetcase = sys.argv[1]
+ if monetcase not in available_cases:
+ print("Usage: python <script.py> <start | stop | cleanup | execute>")
+ sys.exit()
+
+
+
+def monet_start():
+ for i in range(0, len(all_servers)):
+ print(f"Starting mserver on port: {all_servers[i]} and dbpath:
{all_db_paths[i]}")
+ p = subprocess.Popen([f"mserver5 --dbpath={all_db_paths[i]} --set
mapi_port={all_servers[i]} --set monet_daemon=yes"], shell=True)
+
+
+def monet_stop():
+ print(f"Stoping {len(all_servers)} mserver5 instances")
+ p = subprocess.Popen(["t=`pgrep mserver5` && kill -9 $t"], shell=True)
+ p.communicate()
+
+
+def monet_cleanup():
+ for db_path in all_db_paths:
+ print(f"Cleaning directory {db_path}")
+ p = subprocess.Popen([f"rm -rf {db_path}"], shell=True)
+ p.communicate()
+
+
+# Each of the 3 servers holds a table s1 with the same structure (replicated
schema)
+# A query select * from s1 comes to one of the servers. The hitchhiker has to
find all
+# the databases that s1 exists and put the necessary move statements. In this
case it
+# needs to put 3 different statements (since there are 3 mservers holding the
same table)
+# P.S: In this query we are not using merge tables!
+def monet_execute():
+ server = mapi.Connection()
+ for i in range(0, len(all_servers)):
+ database = all_db_paths[i].split("/")[2]
+ server.connect(hostname=hostname, port=all_servers[i],
+ username=username, password=password,
+ database=database, language="sql")
+ if monetcase == "create_tables":
+ server.cmd(f"sCREATE TABLE s1(i INT);")
+ server.cmd(f"sINSERT INTO s1 VALUES ({i + 23}), ({i + 42});")
+ elif monetcase == "execute":
+ # we need to execute the query only on 1 mserver5
+ # the hitchhiker will do the rest of the work
+ server.cmd("sexplain SELECT * FROM s1;")
+ break
+
+
+
+def main():
+ if monetcase == "start":
+ monet_start()
+ elif monetcase == "stop":
+ monet_stop()
+ elif monetcase == "cleanup":
+ monet_cleanup()
+ else:
+ monet_execute()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/monetdb5/optimizer/opt_hitchhiker.c
b/monetdb5/optimizer/opt_hitchhiker.c
--- a/monetdb5/optimizer/opt_hitchhiker.c
+++ b/monetdb5/optimizer/opt_hitchhiker.c
@@ -21,9 +21,21 @@ OPThitchhikerImplementation(Client cntxt
str msg;
char buf[256];
int i, limit, slimit, updates = 0, actions = 0;
+ size_t j;
InstrPtr p, q, *old;
lng clk = GDKusec();
+ // Initialize the landscape - this is hardcoded it needs to be removed
+ // It also assumes that the tables of the query have a replicated schema
+ // and all tables exist on all nodes (see the Python script for more
details)
+ str home_node = "localhost:50000";
+ int next_node_idx = 2;
+ const char* landscape[3] = {
+ "localhost:50000",
+ "localhost:50001",
+ "localhost:50002",
+ };
+
// check if optimizer has been applied
if(optimizerIsApplied(mb, "hh"))
return MAL_SUCCEED;
@@ -52,12 +64,31 @@ OPThitchhikerImplementation(Client cntxt
// if instruction IS sql.tid first inject the new instruction first
if(getModuleId(p) == sqlRef && getFunctionId(p) == tidRef)
{
- // create a new instruction and push it
- q = newInstruction(mb, hitchhikerRef, moveRef);
- getArg(q, 0) = newTmpVariable(mb, TYPE_any);
- // setDestVar(q, newTmpVariable(mb, Typ));
- pushInstruction(mb, q);
- actions++;
+ // SOS: if table s1 is included - this needs to be removed
+ if(strcmp(getVarConstant(mb, getArg(p, 3)).val.sval, "s1") ==
0) {
+
+ // do it if table is s1 - for now
+ // create a new instruction and push it
+ q = newInstruction(mb, hitchhikerRef, moveRef);
+
+ // fill home node
+ q = pushStr(mb, q, home_node);
+
+ // next_arg
+ q = pushInt(mb, q, next_node_idx);
+
+ // landscape-fmt
+ q = pushStr(mb, q, "sss");
+
+ // fill landscape info
+ for(j = 0; j < 3; j++)
+ q = pushStr(mb, q, landscape[j]);
+
+ // getArg(q, 0) = newTmpVariable(mb, TYPE_any);
+ setDestVar(q, newTmpVariable(mb, TYPE_any));
+ pushInstruction(mb, q);
+ actions++;
+ }
}
// push the original instructions
@@ -78,7 +109,7 @@ OPThitchhikerImplementation(Client cntxt
if(msg == MAL_SUCCEED) msg = chkDeclarations(mb);
clk = GDKusec() - clk;
- snprintf(buf, 256, "%-20s actions=%2d time=" LLFMT " usec",
"optimizer.hitchhiker", actions, clk);
+ snprintf(buf, 256, "%-20s actions=%2d time=" LLFMT " usec", "hitchhiker",
actions, clk);
newComment(mb, buf);
addtoMalBlkHistory(mb);
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -294,14 +294,10 @@ unsafe pattern clear_table(sname:str, tn
address mvc_clear_table_wrap
comment "Clear the table sname.tname.";
-
-
-pattern hh.move() :void
+pattern hh.move(home_node:str, next_node_idx:int, landscape:str...) :void
address hh_move
comment "Hitchhiker migrate to another database";
-
-
pattern tid( mvc:int, sname:str, tname:str):bat[:oid]
address SQLtid
comment "Return a column with the valid tuple identifiers associated with the
table sname.tname.";
diff --git a/sql/backends/monet5/sql_hitchhiker.c
b/sql/backends/monet5/sql_hitchhiker.c
--- a/sql/backends/monet5/sql_hitchhiker.c
+++ b/sql/backends/monet5/sql_hitchhiker.c
@@ -17,6 +17,28 @@ hh_move(Client cntxt, MalBlkPtr mb, MalS
(void) mb;
(void) stk;
(void) pci;
+
+ str *home_node, *landscape;
+ int *next_node_idx, idx;
+
+ home_node = getArgReference_str(stk, pci, 1);
+ next_node_idx = getArgReference_int(stk, pci, 2);
+ landscape = getArgReference_str(stk, pci, 3);
+
+ // arguments start from 1!
+ // jump over home_node, next_node_idx and landscape
+ // and get the node that should be visited next
+ idx = 3 + *next_node_idx;
+
+ // modify the next_node_idx in the stack
+ // so the next nodes knows where to jump
+ *next_node_idx += 1;
+ VALset(&stk->stk[pci->argv[1]], TYPE_int, &next_node_idx);
+ next_node_idx = getArgReference_int(stk, pci, 2);
+
+ // connect to the next node
+ // TODO
+
return MAL_SUCCEED;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list