Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6d91fb3

Browse files
committed
Logging to /tmp/shmn.log, create_hash_partitions, logging nodes ids.
1 parent 0d15e64 commit 6d91fb3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

run_shardlord.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import logging
34
from time import sleep
45

56
from testgres import PostgresNode
@@ -11,15 +12,15 @@
1112

1213
class Shardlord(PostgresNode):
1314
def __init__(self, name):
14-
super(Shardlord, self).__init__(name=name, port=5432)
15+
super(Shardlord, self).__init__(name=name, port=5432, use_logging=True)
1516

1617
self.nodes = []
1718

1819
@staticmethod
1920
def _common_conn_string(port):
2021
return (
21-
"host=localhost port={} dbname={} user={}"
22-
).format(port, DBNAME, default_username())
22+
"dbname={} port={} "
23+
).format(DBNAME, port)
2324

2425
@staticmethod
2526
def _common_conf_lines():
@@ -28,6 +29,7 @@ def _common_conf_lines():
2829

2930
"log_min_messages = DEBUG1\n"
3031
"client_min_messages = NOTICE\n"
32+
"log_line_prefix = '%m %z'\n"
3133
"log_replication_commands = on\n"
3234

3335
"synchronous_commit = on\n"
@@ -84,7 +86,7 @@ def add_node(self, name):
8486
config_lines += self._common_conf_lines()
8587

8688
# create a new node
87-
node = get_new_node(name)
89+
node = get_new_node(name, use_logging=True)
8890
self.nodes.append(node)
8991

9092
# start this node
@@ -99,17 +101,25 @@ def add_node(self, name):
99101
add_node_cmd = "select shardman.add_node('{}')".format(conn_string)
100102
self.safe_psql(DBNAME, add_node_cmd)
101103

102-
return self
104+
return node
103105

104106

105107
if __name__ == "__main__":
108+
logfile = "/tmp/shmn.log"
109+
open(logfile, 'w').close() # truncate
110+
logging.basicConfig(filename=logfile, level=logging.DEBUG)
106111
with Shardlord("DarthVader") as lord:
107112
lord.init().start().install()
108113

109-
lord.add_node("Luke")
114+
luke = lord.add_node("Luke")
110115
lord.add_node("ObiVan")
111116
lord.add_node("C3PO")
112117

118+
luke.safe_psql(DBNAME, "drop table if exists pt cascade;")
119+
luke.safe_psql(DBNAME, "CREATE TABLE pt(id INT NOT NULL, payload REAL);")
120+
luke.safe_psql(DBNAME, "INSERT INTO pt SELECT generate_series(1, 10), random();")
121+
lord.safe_psql(DBNAME, "select shardman.create_hash_partitions(2, 'pt', 'id', 4, true);");
122+
113123
print("%s:" % lord.name)
114124
print("\t-> port %i" % lord.port)
115125
print("\t-> dir %s" % lord.base_dir)

0 commit comments

Comments
 (0)