|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use PostgresNode; |
| 5 | +use TestLib; |
| 6 | +use Test::Moretests=> 1; |
| 7 | + |
| 8 | +my%allocated_ports = (); |
| 9 | +suballocate_ports |
| 10 | +{ |
| 11 | +my@allocated_now = (); |
| 12 | +my ($host,$ports_to_alloc) =@_; |
| 13 | + |
| 14 | +while ($ports_to_alloc > 0) |
| 15 | +{ |
| 16 | +my$port =int(rand() * 16384) + 49152; |
| 17 | +nextif$allocated_ports{$port}; |
| 18 | +diag("checking for port$port\n"); |
| 19 | +if (!TestLib::run_log(['pg_isready','-h',$host,'-p',$port])) |
| 20 | +{ |
| 21 | +$allocated_ports{$port} = 1; |
| 22 | +push(@allocated_now,$port); |
| 23 | +$ports_to_alloc--; |
| 24 | +} |
| 25 | +} |
| 26 | + |
| 27 | +return@allocated_now; |
| 28 | +} |
| 29 | + |
| 30 | +my$nnodes = 2; |
| 31 | +my@nodes = (); |
| 32 | + |
| 33 | +diag("creating nodes"); |
| 34 | +foreachmy$i (1..$nnodes) |
| 35 | +{ |
| 36 | +my$host ="127.0.0.1"; |
| 37 | +my ($pgport,$raftport) = allocate_ports($host, 2); |
| 38 | +my$node = new PostgresNode("node$i",$host,$pgport); |
| 39 | +$node->{id} =$i; |
| 40 | +$node->{raftport} =$raftport; |
| 41 | +push(@nodes,$node); |
| 42 | +} |
| 43 | + |
| 44 | +my$mm_connstr =join(',',map {"${\$_->connstr('postgres') }" }@nodes); |
| 45 | +my$raft_peers =join(',',map {join(':',$_->{id},$_->host,$_->{raftport}) }@nodes); |
| 46 | + |
| 47 | +diag("mm_connstr =$mm_connstr\n"); |
| 48 | +diag("raft_peers =$raft_peers\n"); |
| 49 | + |
| 50 | +diag("initting and configuring nodes"); |
| 51 | +foreachmy$node (@nodes) |
| 52 | +{ |
| 53 | +my$id =$node->{id}; |
| 54 | +my$host =$node->host; |
| 55 | +my$pgport =$node->port; |
| 56 | +my$raftport =$node->{raftport}; |
| 57 | + |
| 58 | +$node->init(hba_permit_replication=> 0); |
| 59 | +$node->append_conf("postgresql.conf",qq( |
| 60 | +listen_addresses = '$host' |
| 61 | +unix_socket_directories = '' |
| 62 | +port =$pgport |
| 63 | +max_prepared_transactions = 10 |
| 64 | +max_worker_processes = 10 |
| 65 | +wal_level = logical |
| 66 | +fsync = off |
| 67 | +max_wal_senders = 10 |
| 68 | +wal_sender_timeout = 0 |
| 69 | +max_replication_slots = 10 |
| 70 | +shared_preload_libraries = 'raftable,multimaster' |
| 71 | +multimaster.workers = 4 |
| 72 | +multimaster.queue_size = 10485760 # 10mb |
| 73 | +multimaster.node_id =$id |
| 74 | +multimaster.conn_strings = '$mm_connstr' |
| 75 | +multimaster.use_raftable = true |
| 76 | +raftable.id =$id |
| 77 | +raftable.peers = '$raft_peers' |
| 78 | +)); |
| 79 | + |
| 80 | +$node->append_conf("pg_hba.conf",qq( |
| 81 | +local replication all trust |
| 82 | +host replication all 127.0.0.1/32 trust |
| 83 | +host replication all ::1/128 trust |
| 84 | +)); |
| 85 | +} |
| 86 | + |
| 87 | +diag("starting nodes"); |
| 88 | +foreachmy$node (@nodes) |
| 89 | +{ |
| 90 | +$node->start(); |
| 91 | +} |
| 92 | + |
| 93 | +my ($rc,$out,$err); |
| 94 | + |
| 95 | +diag("sleeping"); |
| 96 | +sleep(10); |
| 97 | + |
| 98 | +my@argv = ('dtmbench'); |
| 99 | +foreachmy$node (@nodes) |
| 100 | +{ |
| 101 | +push(@argv,'-c',$node->connstr('postgres')); |
| 102 | +} |
| 103 | +push(@argv,'-n', 10,'-a', 1000,'-w', 10,'-r', 1); |
| 104 | + |
| 105 | +diag("running dtmbench -i"); |
| 106 | +TestLib::run_log([@argv,'-i']); |
| 107 | + |
| 108 | +diag("running dtmbench"); |
| 109 | +TestLib::run_log(\@argv,'>', \$out); |
| 110 | +if ($out =~/Wrong sum/) |
| 111 | +{ |
| 112 | +fail("inconsistency detected"); |
| 113 | +} |
| 114 | +else |
| 115 | +{ |
| 116 | +pass("all consistent during dtmbench"); |
| 117 | +} |