File: repmgr024.tcl

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (226 lines) | stat: -rw-r--r-- 7,029 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2009, 2013 Oracle and/or its affiliates.  All rights reserved.
#
# TEST	repmgr024
# TEST	Test of group-wide log archiving awareness.
# TEST 	Verify that log archiving will use the ack from the clients in
# TEST	its decisions about what log files are allowed to be archived.
#
proc repmgr024 { { niter 50 } { tnum 024 } args } {
	source ./include.tcl

	if { $is_freebsd_test == 1 } {
		puts "Skipping replication manager test on FreeBSD platform."
		return
	}

	# QNX does not support fork() in a multi-threaded environment.
	if { $is_qnx_test } {
		puts "Skipping repmgr$tnum on QNX."
		return
	}

	set method "btree"
	set args [convert_args $method $args]
	puts "Repmgr$tnum ($method): group wide log archiving."
	repmgr024_sub $method $niter $tnum $args
}

proc repmgr024_sub { method niter tnum largs } {
	global testdir
	global util_path
	global databases_in_memory
	global repfiles_in_memory
	global rep_verbose
	global verbose_type

	set verbargs ""
	if { $rep_verbose == 1 } {
		set verbargs " -verbose {$verbose_type on} "
	}

	set repmemargs ""
	if { $repfiles_in_memory } {
		set repmemargs "-rep_inmem_files "
	}

	env_cleanup $testdir
	file mkdir [set dira $testdir/SITE_A]
	file mkdir [set dirb $testdir/SITE_B]
	file mkdir [set dirc $testdir/SITE_C]
	foreach { porta portb portc } [available_ports 3] {}

	# Log size is small so we quickly create more than one.
	# The documentation says that the log file must be at least
	# four times the size of the in-memory log buffer.
	set pagesize 4096
	append largs " -pagesize $pagesize "
	set log_buf [expr $pagesize * 2]
	set log_max [expr $log_buf * 4]

	set cmda "berkdb_env_noerr -create -txn nosync \
	    $verbargs $repmemargs -rep -thread \
	    -log_buffer $log_buf -log_max $log_max -errpfx SITE_A \
	    -home $dira"
	set enva [eval $cmda]
	# Use quorum ack policy (default, therefore not specified)
	# otherwise it will never wait when
	# the client is closed and we want to give it a chance to
	# wait later in the test.
	$enva repmgr -timeout {connection_retry 5000000} \
	    -local [list 127.0.0.1 $porta] -start master

	set cmdb "berkdb_env_noerr -create -txn nosync \
	    $verbargs $repmemargs -rep -thread \
	    -log_buffer $log_buf -log_max $log_max -errpfx SITE_B \
	    -home $dirb"
	set envb [eval $cmdb]
	$envb repmgr -timeout {connection_retry 5000000} \
	    -local [list 127.0.0.1 $portb] -start client \
	    -remote [list 127.0.0.1 $porta]
	puts "\tRepmgr$tnum.a: wait for client B to sync with master."
	await_startup_done $envb

	set cmdc "berkdb_env_noerr -create -txn nosync \
	    $verbargs $repmemargs -rep -thread \
	    -log_buffer $log_buf -log_max $log_max -errpfx SITE_C \
	    -home $dirc"
	set envc [eval $cmdc]
	$envc repmgr -timeout {connection_retry 5000000} \
	    -local [list 127.0.0.1 $portc] -start client \
	    -remote [list 127.0.0.1 $porta]
	puts "\tRepmgr$tnum.b: wait for client C to sync with master."
	await_startup_done $envc


	# Clobber replication's 30-second anti-archive timer, which will have
	# been started by client sync-up internal init, so that we can do a
	# log_archive in a moment.
	#
	$enva test force noarchive_timeout

	set stop 0
	set start 0
	while { $stop == 0 } {
		# Run rep_test in the master.
		puts "\tRepmgr$tnum.c: Running rep_test in replicated env."
		eval rep_test $method $enva NULL $niter $start 0 0 $largs
		incr start $niter

		set res [eval exec $util_path/db_archive -h $dira]
		if { [llength $res] != 0 } {
			set stop 1
		}
	}
	# Save list of files for later.
	set files_arch $res

	puts "\tRepmgr$tnum.d: Close client."
	$envc close

	# Now that the client closed its connection, verify that
	# we cannot archive files.
	#
	# When a connection is closed, repmgr updates the 30 second
	# noarchive timestamp in order to give the client process a
	# chance to restart and rejoin the group.  We verify that
	# when the connection is closed the master cannot archive.
	# due to the 30-second timer.
	#
	set res [eval exec $util_path/db_archive -h $dira]
	error_check_good files_archivable_closed [llength $res] 0

	#
	# Clobber the 30-second timer and verify we can again archive the
	# files.
	#
	$enva test force noarchive_timeout
	set res [eval exec $util_path/db_archive -h $dira]
	error_check_good files_arch2 $files_arch $res

	set res [eval exec $util_path/db_archive -l -h $dirc]
	set last_client_log [lindex [lsort $res] end]

	set stop 0
	while { $stop == 0 } {
		# Run rep_test in the master.
		puts "\tRepmgr$tnum.e: Running rep_test in replicated env."
		eval rep_test $method $enva NULL $niter $start 0 0 $largs
		incr start $niter

		# We use log_archive when we want to remove log files so
		# that if we are running verbose, we get all of the output
		# we might need.
		#
		# However, we can use db_archive for all of the other uses
		# we need such as getting a list of what log files exist in
		# the environment.
		#
		puts "\tRepmgr$tnum.f: Run log_archive on master."
		set res [$enva log_archive -arch_remove]
		set res [eval exec $util_path/db_archive -l -h $dira]
		if { [lsearch -exact $res $last_client_log] == -1 } {
			set stop 1
		}
	}

	#
	# Get the new last log file for client 1.
	#
	set res [eval exec $util_path/db_archive -l -h $dirb]
	set last_client_log [lindex [lsort $res] end]

	#
	# Set test hook to prevent client 1 from sending any ACKs,
	# but remaining alive.
	#
	puts "\tRepmgr$tnum.g: Turn off acks via test hook on remaining client."
	$envb test abort repmgr_perm

	#
	# Advance logfiles again.
	set stop 0
	while { $stop == 0 } {
		# Run rep_test in the master.
		puts "\tRepmgr$tnum.h: Running rep_test in replicated env."
		eval rep_test $method $enva NULL $niter $start 0 0 $largs
		incr start $niter

		puts "\tRepmgr$tnum.i: Run db_archive on master."
		set res [eval exec $util_path/db_archive -l -h $dira]
		set last_master_log [lindex [lsort $res] end]
		if { $last_master_log != $last_client_log } {
			set stop 1
		}
	}

	#
	# Make sure neither log_archive in same process nor db_archive
	# in a different process show any files to archive.
	#
	error_check_good no_files_log_archive [llength [$enva log_archive]] 0
	set dbarchres [eval exec $util_path/db_archive -h $dira]
	error_check_good no_files_db_archive [llength $dbarchres] 0

	puts "\tRepmgr$tnum.j: Try to archive. Verify it didn't."
	set res [$enva log_archive -arch_remove]
	set res [eval exec $util_path/db_archive -l -h $dira]
	error_check_bad cl1_archive [lsearch -exact $res $last_client_log] -1
	#
	# Turn off test hook preventing acks.  Then run a perm operation
	# so that the client can send its ack.
	#
	puts "\tRepmgr$tnum.k: Enable acks and archive again."
	$envb test abort none
	$enva txn_checkpoint -force
	#
	# Now archive again and make sure files were removed.
	#
	set res [$enva log_archive -arch_remove]
	set res [eval exec $util_path/db_archive -l -h $dira]
	error_check_good cl1_archive [lsearch -exact $res $last_client_log] -1

	$enva close
	$envb close
}