1
1
#!/usr/bin/env python
2
2
3
+ import logging
3
4
from time import sleep
4
5
5
6
from testgres import PostgresNode
11
12
12
13
class Shardlord (PostgresNode ):
13
14
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 )
15
16
16
17
self .nodes = []
17
18
18
19
@staticmethod
19
20
def _common_conn_string (port ):
20
21
return (
21
- "host=localhost port={} dbname={} user ={}"
22
- ).format (port , DBNAME , default_username () )
22
+ "dbname={} port ={} "
23
+ ).format (DBNAME , port )
23
24
24
25
@staticmethod
25
26
def _common_conf_lines ():
@@ -28,6 +29,7 @@ def _common_conf_lines():
28
29
29
30
"log_min_messages = DEBUG1\n "
30
31
"client_min_messages = NOTICE\n "
32
+ "log_line_prefix = '%m %z'\n "
31
33
"log_replication_commands = on\n "
32
34
33
35
"synchronous_commit = on\n "
@@ -84,7 +86,7 @@ def add_node(self, name):
84
86
config_lines += self ._common_conf_lines ()
85
87
86
88
# create a new node
87
- node = get_new_node (name )
89
+ node = get_new_node (name , use_logging = True )
88
90
self .nodes .append (node )
89
91
90
92
# start this node
@@ -99,17 +101,25 @@ def add_node(self, name):
99
101
add_node_cmd = "select shardman.add_node('{}')" .format (conn_string )
100
102
self .safe_psql (DBNAME , add_node_cmd )
101
103
102
- return self
104
+ return node
103
105
104
106
105
107
if __name__ == "__main__" :
108
+ logfile = "/tmp/shmn.log"
109
+ open (logfile , 'w' ).close () # truncate
110
+ logging .basicConfig (filename = logfile , level = logging .DEBUG )
106
111
with Shardlord ("DarthVader" ) as lord :
107
112
lord .init ().start ().install ()
108
113
109
- lord .add_node ("Luke" )
114
+ luke = lord .add_node ("Luke" )
110
115
lord .add_node ("ObiVan" )
111
116
lord .add_node ("C3PO" )
112
117
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
+
113
123
print ("%s:" % lord .name )
114
124
print ("\t -> port %i" % lord .port )
115
125
print ("\t -> dir %s" % lord .base_dir )
0 commit comments