1# Copyright (c) 2009, 2020 Oracle and/or its affiliates.  All rights reserved.
2#
3# See the file LICENSE for license information.
4#
5# $Id$
6#
7# TEST    env017
8# TEST    Check documented "stat" fields against the fields
9# TEST    returned by the "stat" functions.  Make sure they
10# TEST    match, and that none are missing.
11# TEST    These are the stat functions we test:
12# TEST        env log_stat
13# TEST        env lock_stat
14# TEST        env txn_stat
15# TEST        env mutex_stat
16# TEST        env rep_stat
17# TEST        env repmgr_stat
18# TEST        env mpool_stat
19# TEST        db stat
20# TEST        seq stat
21# TEST        db compact_stat
22
23
24proc env017 { } {
25	puts "\nEnv017: Check the integrity of the various stat"
26	env017_log_stat
27	env017_lock_stat
28	env017_txn_stat
29	env017_mutex_stat
30	env017_rep_stat
31	env017_repmgr_stat
32	env017_mpool_stat
33	env017_db_stat
34	env017_seq_stat
35	env017_compact_stat
36}
37
38# Check the log stat field.
39proc env017_log_stat { } {
40	puts "\nEnv017: Check the Log stat field"
41	set check_type log_stat_check
42	set stat_method log_stat
43	set envargs {-create -log}
44	set map_list {
45		{ "Magic"	    st_magic }
46		{ "Log file Version"	    st_version }
47		{ "Region size"	    st_regsize }
48		{ "Log file mode"	    st_mode }
49		{ "Log record cache size"	    st_lg_bsize }
50		{ "Current log file size"	    st_lg_size }
51		{ "Initial fileid allocation"	    st_fileid_init }
52		{ "Current fileids in use"	    st_nfileid }
53		{ "Maximum fileids ever used"	    st_maxnfileid }
54		{ "Log file records written"	    st_record }
55		{ "Mbytes written"	    st_w_mbytes }
56		{ "Bytes written (over Mb)"	    st_w_bytes }
57		{ "Mbytes written since checkpoint"	    st_wc_mbytes }
58		{ "Bytes written (over Mb) since checkpoint"
59		    st_wc_bytes }
60		{ "Times log written"	    st_wcount }
61		{ "Times log written because cache filled up"
62		    st_wcount_fill }
63		{ "Times log read from disk"	    st_rcount }
64		{ "Times log flushed to disk"	    st_scount }
65		{ "Current log file number"	    st_cur_file }
66		{ "Current log file offset"	    st_cur_offset }
67		{ "On-disk log file number"	    st_disk_file }
68		{ "On-disk log file offset"	    st_disk_offset }
69		{ "Max commits in a log flush"	    st_maxcommitperflush }
70		{ "Min commits in a log flush"	    st_mincommitperflush }
71		{ "Number of region lock waits"	    st_region_wait }
72		{ "Number of region lock nowaits"	    st_region_nowait }
73	}
74	set doc_list [list st_magic st_version st_mode st_lg_bsize st_lg_size \
75	    st_fileid_init st_nfileid st_maxnfileid \
76	    st_record st_w_mbytes st_w_bytes st_wc_mbytes st_wc_bytes \
77	    st_wcount st_wcount_fill st_rcount st_scount st_cur_file \
78	    st_cur_offset st_disk_file st_disk_offset st_maxcommitperflush \
79	    st_mincommitperflush st_regsize st_region_wait st_region_nowait ]
80	env017_stat_check \
81	    $map_list $doc_list $check_type $stat_method $envargs
82}
83
84# Check the lock stat field.
85proc env017_lock_stat { } {
86	puts "\nEnv017: Check the lock stat field"
87	set check_type lock_stat_check
88	set stat_method lock_stat
89	set envargs {-create -lock}
90	set map_list {
91		{ "Region size"	    st_regsize }
92		{ "Last allocated locker ID"	    st_id }
93		{ "Current maximum unused locker ID"	    st_cur_maxid }
94		{ "Initial locks"	    st_initlocks }
95		{ "Allocated locks"	    st_locks }
96		{ "Maximum locks"	    st_maxlocks }
97		{ "Initial lockers"	    st_initlockers }
98		{ "Allocated lockers"	    st_lockers }
99		{ "Maximum lockers"	    st_maxlockers }
100		{ "Initial objects"	    st_initobjects }
101		{ "Allocated objects"	    st_objects }
102		{ "Maximum objects"	    st_maxobjects }
103		{ "Lock modes"	    st_nmodes }
104		{ "Number of lock table partitions"	    st_partitions }
105		{ "Size of object hash table"	st_tablesize }
106		{ "Current number of locks"	    st_nlocks }
107		{ "Maximum number of locks so far"	    st_maxnlocks }
108		{ "Maximum number of locks in any hash bucket"
109    		    st_maxhlocks }
110		{ "Maximum number of lock steals for an empty partition"
111		    st_locksteals }
112		{ "Maximum number lock steals in any partition"
113		    st_maxlsteals }
114		{ "Current number of lockers"	    st_nlockers }
115		{ "Maximum number of lockers so far"	    st_maxnlockers }
116		{ "Number of hits in the thread locker cache"
117		    st_nlockers_hit }
118		{ "Total number of lockers reused"  st_nlockers_reused }
119		{ "Current number of objects"	    st_nobjects }
120		{ "Maximum number of objects so far"	    st_maxnobjects }
121		{ "Maximum number of objects in any hash bucket"
122		    st_maxhobjects }
123		{ "Maximum number of object steals for an empty partition"
124		    st_objectsteals }
125		{ "Maximum number object steals in any partition"
126		    st_maxosteals }
127		{ "Lock requests"	    st_nrequests }
128		{ "Lock releases"	    st_nreleases }
129		{ "Lock upgrades"	    st_nupgrade }
130		{ "Lock downgrades"	    st_ndowngrade }
131		{ "Number of conflicted locks for which we waited"
132		    st_lock_wait }
133		{ "Number of conflicted locks for which we did not wait"
134		    st_lock_nowait }
135		{ "Deadlocks detected"	    st_ndeadlocks }
136		{ "Number of region lock waits"	    st_region_wait }
137		{ "Number of region lock nowaits"	    st_region_nowait }
138		{ "Number of object allocation waits"	    st_objs_wait }
139		{ "Number of object allocation nowaits"	    st_objs_nowait }
140		{ "Number of locker allocation waits"	    st_lockers_wait }
141		{ "Number of locker allocation nowaits"	    st_lockers_nowait }
142		{ "Maximum hash bucket length"	    st_hash_len }
143		{ "Lock timeout value"	    st_locktimeout }
144		{ "Number of lock timeouts"	    st_nlocktimeouts }
145		{ "Transaction timeout value"	    st_txntimeout }
146		{ "Number of transaction timeouts"	    st_ntxntimeouts }
147		{ "Number lock partition mutex waits"	    st_part_wait }
148		{ "Number lock partition mutex nowaits"	    st_part_nowait }
149		{ "Maximum number waits on any lock partition mutex"
150		    st_part_max_wait }
151		{ "Maximum number nowaits on any lock partition mutex"
152		    st_part_max_nowait }
153	}
154	set doc_list [list st_id st_cur_maxid st_nmodes \
155	    st_initlocks st_initlockers st_initobjects \
156	    st_locks st_lockers st_objects \
157	    st_maxlocks st_maxlockers st_maxobjects \
158	    st_partitions st_tablesize st_nlocks st_maxnlocks \
159	    st_maxhlocks st_locksteals st_maxlsteals st_nlockers \
160	    st_maxnlockers st_nlockers_hit st_nlockers_reused st_nobjects \
161	    st_maxnobjects st_maxhobjects st_objectsteals st_maxosteals \
162	    st_nrequests st_nreleases st_nupgrade st_ndowngrade st_lock_wait \
163	    st_lock_nowait st_ndeadlocks st_locktimeout st_nlocktimeouts \
164	    st_txntimeout st_ntxntimeouts st_objs_wait st_objs_nowait \
165	    st_lockers_wait st_lockers_nowait st_hash_len st_regsize \
166	    st_part_wait st_part_nowait st_part_max_wait st_part_max_nowait \
167	    st_region_wait st_region_nowait]
168	env017_stat_check \
169	    $map_list $doc_list $check_type $stat_method $envargs
170}
171
172# Check the txn stat field.
173proc env017_txn_stat { } {
174	puts "\nEnv017: Check the transaction stat field"
175	set check_type txn_stat_check
176	set stat_method txn_stat
177	set envargs {-create -txn}
178	set map_list {
179		{ "Region size"	    st_regsize }
180		{ "LSN of last checkpoint"	    st_last_ckp }
181		{ "Time of last checkpoint"	    st_time_ckp }
182		{ "Last txn ID allocated"	    st_last_txnid }
183		{ "Maximum txns"	    st_maxtxns }
184		{ "Initial txns"	    st_inittxns }
185		{ "Number aborted txns"	    st_naborts }
186		{ "Number txns begun"	    st_nbegins }
187		{ "Number committed txns"	    st_ncommits }
188		{ "Number active txns"	    st_nactive }
189		{ "Number of snapshot txns"	    st_nsnapshot }
190		{ "Number restored txns"	    st_nrestores }
191		{ "Maximum active txns"	    st_maxnactive }
192		{ "Maximum snapshot txns"	    st_maxnsnapshot }
193		{ "Number of region lock waits"	    st_region_wait }
194		{ "Number of region lock nowaits"	    st_region_nowait }
195	}
196	set doc_list [list  st_last_ckp st_time_ckp st_last_txnid st_maxtxns \
197	    st_inittxns st_nactive st_nsnapshot st_maxnactive st_maxnsnapshot \
198	    st_nbegins st_naborts st_ncommits st_nrestores st_regsize \
199	    st_region_wait st_region_nowait ]
200	env017_stat_check \
201	    $map_list $doc_list $check_type $stat_method $envargs
202}
203
204#Check the mutex stat field.
205proc env017_mutex_stat { } {
206	puts "\nEnv017: Check the mutex stat field"
207	set check_type mutex_stat_check
208	set stat_method mutex_stat
209	set envargs {-create}
210	set map_list {
211		{ "Mutex align"	    st_mutex_align }
212		{ "Mutex TAS spins"	    st_mutex_tas_spins }
213		{ "Initial mutex count"	st_mutex_init }
214		{ "Mutex count"	    st_mutex_cnt }
215		{ "Mutex max"	st_mutex_max }
216		{ "Free mutexes"	    st_mutex_free }
217		{ "Mutexes in use"	    st_mutex_inuse }
218		{ "Max mutexes in use"	    st_mutex_inuse_max }
219		{ "Mutex region size"	    st_regsize }
220		{ "Mutex region max"	    st_regmax }
221		{ "Number of region waits"	    st_region_wait }
222		{ "Number of region no waits"	    st_region_nowait }
223	}
224	set doc_list [list st_mutex_align st_mutex_tas_spins st_mutex_init \
225	    st_mutex_cnt st_mutex_max st_mutex_free st_mutex_inuse \
226	    st_mutex_inuse_max st_regsize st_regmax st_region_wait \
227	    st_region_nowait ]
228
229	env017_stat_check \
230	    $map_list $doc_list $check_type $stat_method $envargs
231}
232
233# Check the rep stat field.
234proc env017_rep_stat { } {
235	puts "\nEnv017: Check the replication stat field"
236	set check_type rep_stat_check
237	set stat_method rep_stat
238	set envargs {-create -rep -log -txn}
239	set map_list {
240		{ "Role"	    st_status}
241		{ "Next LSN expected"	    st_next_lsn }
242		{ "First missed LSN"	    st_waiting_lsn }
243		{ "Maximum permanent LSN"	    st_max_perm_lsn }
244		{ "External files found deleted"    st_ext_deleted }
245		{ "External files duplicated"	    st_ext_duplicated }
246		{ "External file data messages recieved"	    \
247		      st_ext_records }
248		{ "External file data messages re-requested"     st_ext_rereq }
249		{ "External files found truncated"  st_ext_truncated }
250		{ "External file updates re-requested"	    st_ext_update_rereq }
251		{ "Bulk buffer fills"	    st_bulk_fills }
252		{ "Bulk buffer overflows"	    st_bulk_overflows }
253		{ "Bulk records stored"	    st_bulk_records }
254		{ "Bulk buffer transfers"	    st_bulk_transfers }
255		{ "Client service requests"	    st_client_svc_req }
256		{ "Client service req misses"	    st_client_svc_miss }
257		{ "Client rerequests"	    st_client_rerequests }
258		{ "Duplicate master conditions"	    st_dupmasters }
259		{ "Environment ID"	    st_env_id }
260		{ "Environment priority"	    st_env_priority }
261		{ "Generation number"	    st_gen }
262		{ "Election generation number"	    st_egen }
263		{ "Startup complete"	    st_startup_complete }
264		{ "Lease messages sent"		st_lease_sends }
265		{ "Lease checks"		st_lease_chk }
266		{ "Lease check invalid"		st_lease_chk_misses }
267		{ "Lease check refresh"		st_lease_chk_refresh }
268		{ "Duplicate log records received"	    st_log_duplicated }
269		{ "Current log records queued"	    st_log_queued }
270		{ "Maximum log records queued"	    st_log_queued_max }
271		{ "Total log records queued"	    st_log_queued_total }
272		{ "Log records received"	    st_log_records }
273		{ "Log records requested"	    st_log_requested }
274		{ "Master environment ID"	    st_master }
275		{ "Master changes"	    st_master_changes }
276		{ "Messages with bad generation number"	    st_msgs_badgen }
277		{ "Messages processed"	    st_msgs_processed }
278		{ "Messages ignored for recovery"	    st_msgs_recover }
279		{ "Message send failures"	    st_msgs_send_failures }
280		{ "Messages sent"	    st_msgs_sent }
281		{ "New site messages"	    st_newsites }
282		{ "Number of sites in replication group"	    st_nsites }
283		{ "Transmission limited"	    st_nthrottles }
284		{ "Outdated conditions"	    st_outdated }
285		{ "Transactions applied"	    st_txns_applied }
286		{ "Next page expected"	    st_next_pg }
287		{ "First missed page"	    st_waiting_pg }
288		{ "Duplicate pages received"	    st_pg_duplicated }
289		{ "Pages received"	    st_pg_records }
290		{ "Pages requested"	    st_pg_requested }
291		{ "Elections held"	    st_elections }
292		{ "Elections won"	    st_elections_won }
293		{ "Election phase"	    st_election_status }
294		{ "Election winner"	    st_election_cur_winner }
295		{ "Election winner generation number"	    st_election_gen }
296		{ "Election data generation number"	    st_election_datagen }
297		{ "Election max LSN"	    st_election_lsn }
298		{ "Election sites"	    st_election_nsites }
299		{ "Election nvotes"	    st_election_nvotes }
300		{ "Election priority"	    st_election_priority }
301		{ "Election tiebreaker"	    st_election_tiebreaker }
302		{ "Election votes"	    st_election_votes }
303		{ "Election seconds"	    st_election_sec }
304		{ "Election usecs"	    st_election_usec }
305		{ "Start-sync operations delayed"
306		    st_startsync_delayed }
307		{ "Maximum lease seconds"	    st_max_lease_sec }
308		{ "Maximum lease usecs"	    st_max_lease_usec }
309		{ "File fail cleanups done"	st_filefail_cleanups }
310		{ "Is view"		st_view }
311		{ "Future duplicated log records" 	st_log_futuredup }
312	}
313	set doc_list [list st_ext_deleted st_ext_duplicated \
314	    st_ext_records st_ext_rereq st_ext_truncated st_ext_update_rereq \
315	    st_bulk_fills st_bulk_overflows st_bulk_records \
316	    st_bulk_transfers st_client_rerequests st_client_svc_miss \
317	    st_client_svc_req st_dupmasters st_egen st_election_cur_winner \
318	    st_election_gen st_election_datagen st_election_lsn st_election_nsites \
319	    st_election_nvotes st_election_priority st_election_sec \
320	    st_election_status st_election_tiebreaker st_election_usec \
321	    st_election_votes st_elections st_elections_won st_env_id \
322	    st_env_priority st_filefail_cleanups st_gen st_lease_sends \
323	    st_lease_chk st_lease_chk_misses st_lease_chk_refresh \
324	    st_log_duplicated st_log_futuredup \
325	    st_log_queued st_log_queued_max st_log_queued_total st_log_records \
326	    st_log_requested st_master st_master_changes st_max_lease_sec \
327	    st_max_lease_usec st_max_perm_lsn st_msgs_badgen st_msgs_processed\
328	    st_msgs_recover st_msgs_send_failures st_msgs_sent st_newsites \
329	    st_next_lsn st_next_pg st_nsites st_nthrottles st_outdated \
330	    st_pg_duplicated st_pg_records st_pg_requested \
331	    st_startsync_delayed st_startup_complete st_status \
332	    st_txns_applied st_view st_waiting_lsn st_waiting_pg ]
333	env017_stat_check \
334	    $map_list $doc_list $check_type $stat_method $envargs
335}
336
337# Check the repmgr stat field.
338proc env017_repmgr_stat { } {
339	puts "\nEnv017: Check the repmgr stat field"
340	set check_type repmgr_stat_check
341	set stat_method repmgr_stat
342	set envargs {-create -txn -rep}
343	set map_list {
344		{ "Acknowledgement failures"	    st_perm_failed }
345		{ "Messages delayed"	    st_msgs_queued}
346		{ "Messages discarded"	    st_msgs_dropped}
347		{ "Connections dropped"	    st_connection_drop}
348		{ "Failed re-connects"	    st_connect_fail}
349		{ "Election threads"	    st_elect_threads}
350		{ "Group stable log file"   st_group_stable_log_file}
351		{ "Max elect threads"	    st_max_elect_threads}
352		{ "Total sites"		    st_site_total}
353		{ "View sites"		    st_site_views}
354		{ "Participant sites"	    st_site_participants}
355		{ "Automatic replication process takeovers"	st_takeovers }
356		{ "Incoming messages size (gbytes)"	st_incoming_queue_gbytes }
357		{ "Incoming messages size (bytes)"	st_incoming_queue_bytes }
358		{ "Incoming messages discarded"		st_incoming_msgs_dropped }
359		{ "Forwarded write operations received"	st_write_ops_received }
360		{ "Write operations forwarded"		st_write_ops_forwarded }
361		{ "Replication Manager Polling method"	st_polling_method }
362	}
363	set doc_list [list st_perm_failed st_msgs_queued st_msgs_dropped \
364	    st_connection_drop st_connect_fail st_elect_threads \
365	    st_group_stable_log_file \
366	    st_max_elect_threads st_site_total st_site_views \
367	    st_site_participants st_takeovers st_incoming_queue_gbytes \
368	    st_incoming_queue_bytes st_incoming_msgs_dropped \
369	    st_write_ops_received st_write_ops_forwarded st_polling_method]
370	env017_stat_check \
371	    $map_list $doc_list $check_type $stat_method $envargs
372}
373
374# Check the mpool stat field.
375proc env017_mpool_stat { } {
376	puts "\nEnv017: Check the mpool stat field"
377	set check_type mpool_stat_check
378	set stat_method mpool_stat
379	set envargs {-create}
380	set gsp_map_list {
381		{ "Cache size (gbytes)"	    st_gbytes }
382		{ "Cache size (bytes)"	    st_bytes }
383		{ "Number of caches"	    st_ncache }
384		{ "Maximum number of caches"	    st_max_ncache }
385		{ "Region size"	    st_regsize }
386		{ "Region max"	    st_regmax }
387		{ "Maximum memory-mapped file size"	    st_mmapsize }
388		{ "Maximum open file descriptors"	    st_maxopenfd }
389		{ "Maximum sequential buffer writes"	    st_maxwrite }
390		{ "Sleep after writing maximum buffers"	    st_maxwrite_sleep }
391		{ "Pages mapped into address space"	    st_map }
392		{ "Cache hits"	    st_cache_hit }
393		{ "Cache misses"	    st_cache_miss }
394		{ "Pages created"	    st_page_create }
395		{ "Pages read in"	    st_page_in }
396		{ "Pages written"	    st_page_out }
397		{ "Clean page evictions"	    st_ro_evict }
398		{ "Dirty page evictions"	    st_rw_evict }
399		{ "Dirty pages trickled"	    st_page_trickle }
400		{ "Cached pages"	    st_pages }
401		{ "Cached clean pages"	    st_page_clean }
402		{ "Cached dirty pages"	    st_page_dirty }
403		{ "Hash buckets"	    st_hash_buckets }
404		{ "Mutexes for hash buckets"	    st_hash_mutexes }
405		{ "Default pagesize"	    st_pagesize }
406		{ "Hash lookups"	    st_hash_searches }
407		{ "Longest hash chain found"	    st_hash_longest }
408		{ "Hash elements examined"	    st_hash_examined }
409		{ "Number of hash bucket nowaits"	    st_hash_nowait }
410		{ "Number of hash bucket waits"	    st_hash_wait }
411		{ "Maximum number of hash bucket nowaits"
412		    st_hash_max_nowait }
413		{ "Maximum number of hash bucket waits"	    st_hash_max_wait }
414		{ "Number of region lock nowaits"	    st_region_nowait }
415		{ "Number of region lock waits"	    st_region_wait }
416		{ "Buffers frozen"	    st_mvcc_frozen }
417		{ "Buffers thawed"	    st_mvcc_thawed }
418		{ "Frozen buffers freed"	    st_mvcc_freed }
419		{ "The number of outdated intermediate versions reused"
420		    st_mvcc_reused }
421		{ "Page allocations"	    st_alloc }
422		{ "Buckets examined during allocation"	    st_alloc_buckets }
423		{ "Maximum buckets examined during allocation"
424		    st_alloc_max_buckets }
425		{ "Pages examined during allocation"	    st_alloc_pages }
426		{ "Maximum pages examined during allocation"
427		    st_alloc_max_pages }
428		{ "Threads waiting on buffer I/O"    st_io_wait}
429		{ "Number of syncs interrupted"		st_sync_interrupted}
430		{ "Odd file size detected"		st_oddfsize_detect}
431		{ "Odd file size resolved"		st_oddfsize_resolve}
432	}
433	set fsp_map_list {
434		{ "File Name"		file_name}
435		{ "Page size"		st_pagesize}
436		{ "Pages mapped into address space"		st_map}
437		{ "Cache hits"		st_cache_hit}
438		{ "Cache misses"		st_cache_miss}
439		{ "Pages created"		st_page_create}
440		{ "Pages read in"		st_page_in}
441		{ "Pages written"		st_page_out}
442		{ "Backup spins"		st_backup_spins}
443	}
444	set gsp_doc_list [list st_gbytes st_bytes st_ncache st_max_ncache \
445	    st_regsize st_regmax st_mmapsize st_maxopenfd st_maxwrite \
446	    st_maxwrite_sleep st_map st_cache_hit st_cache_miss \
447	    st_page_create st_page_in st_page_out st_ro_evict st_rw_evict \
448	    st_page_trickle st_pages st_page_clean st_page_dirty \
449	    st_hash_buckets st_hash_mutexes st_pagesize st_hash_searches \
450	    st_hash_longest st_hash_examined st_hash_nowait st_hash_wait \
451	    st_hash_max_nowait st_hash_max_wait st_region_wait \
452	    st_region_nowait st_mvcc_frozen st_mvcc_thawed st_mvcc_freed \
453	    st_mvcc_reused \
454	    st_alloc st_alloc_buckets st_alloc_max_buckets st_alloc_pages \
455	    st_alloc_max_pages st_io_wait st_sync_interrupted \
456	    st_oddfsize_detect st_oddfsize_resolve]
457	set fsp_doc_list [list file_name st_pagesize st_map st_cache_hit \
458	    st_cache_miss st_page_create st_page_in st_page_out st_backup_spins]
459	env017_stat_check \
460	    $gsp_map_list $gsp_doc_list $check_type $stat_method $envargs
461	env017_mpstat_check $gsp_map_list $fsp_map_list \
462	    $gsp_doc_list $fsp_doc_list $check_type $stat_method $envargs
463}
464
465# Check the db stat field.
466proc env017_db_stat { } {
467	puts "\nEnv017: Check the db stat field"
468	set hash_map_list {
469		{ "Magic"	    hash_magic }
470		{ "Version"	    hash_version }
471		{ "Page size"	    hash_pagesize }
472		{ "Page count"	    hash_pagecnt }
473		{ "Number of keys"	    hash_nkeys }
474		{ "Number of records"	    hash_ndata }
475		{ "Number of external files" hash_ext_files }
476		{ "Fill factor"	    hash_ffactor }
477		{ "Buckets"	    hash_buckets }
478		{ "Free pages"	    hash_free }
479		{ "Bytes free"	    hash_bfree }
480		{ "Number of big pages"	    hash_bigpages }
481		{ "Big pages bytes free"	    hash_big_bfree }
482		{ "Overflow pages"	    hash_overflows }
483		{ "Overflow bytes free"	    hash_ovfl_free }
484		{ "Duplicate pages"	    hash_dup }
485		{ "Duplicate pages bytes free"	    hash_dup_free }
486		{ "Flags"	flags }
487	}
488	set heap_map_list {
489		{ "Magic"	    heap_magic }
490		{ "Version"	    heap_version }
491		{ "Number of external files"         heap_ext_files }
492		{ "Number of records"	    heap_nrecs }
493		{ "Page size"	    heap_pagesize }
494		{ "Page count"	    heap_pagecnt }
495		{ "Number of regions"	    heap_nregions }
496		{ "Number of pages in a region"	    heap_regionsize }
497		{ "Flags"	flags }
498	}
499	set queue_map_list {
500		{ "Magic"	    qs_magic }
501		{ "Version"	    qs_version }
502		{ "Page size"	    qs_pagesize }
503		{ "Extent size"	    qs_extentsize }
504		{ "Number of keys"	qs_nkeys }
505		{ "Number of records"	    qs_ndata }
506		{ "Record length"	    qs_re_len }
507		{ "Record pad"	    qs_re_pad }
508		{ "First record number"	    qs_first_recno }
509		{ "Next available record number"	    qs_cur_recno }
510		{ "Number of pages"	    qs_pages }
511		{ "Bytes free"	    qs_pgfree}
512		{ "Flags"	flags }
513	}
514	set btree_map_list {
515		{ "Magic"	    bt_magic }
516		{ "Version"	    bt_version }
517		{ "Number of keys"	    bt_nkeys }
518		{ "Number of records"	    bt_ndata }
519		{ "Number of external files"         bt_ext_files }
520		{ "Minimum keys per page"	    bt_minkey }
521		{ "Fixed record length"	    bt_re_len }
522		{ "Record pad"	    bt_re_pad }
523		{ "Page size"	    bt_pagesize }
524		{ "Page count"	    bt_pagecnt }
525		{ "Levels"	    bt_levels }
526		{ "Internal pages"	    bt_int_pg }
527		{ "Leaf pages"	    bt_leaf_pg }
528		{ "Duplicate pages"	    bt_dup_pg }
529		{ "Overflow pages"	    bt_over_pg }
530		{ "Empty pages"	    bt_empty_pg }
531		{ "Pages on freelist"	    bt_free }
532		{ "Internal pages bytes free"	    bt_int_pgfree }
533		{ "Leaf pages bytes free"	    bt_leaf_pgfree }
534		{ "Duplicate pages bytes free"	    bt_dup_pgfree }
535		{ "Bytes free in overflow pages"	    bt_over_pgfree }
536		{ "Flags"	flags }
537	}
538	set hash_doc_list [list hash_magic hash_version hash_nkeys hash_ndata \
539	    hash_ext_files hash_pagecnt hash_pagesize hash_ffactor hash_buckets \
540	    hash_free hash_bfree hash_bigpages hash_big_bfree hash_overflows \
541	    hash_ovfl_free hash_dup hash_dup_free flags]
542
543	set heap_doc_list [list heap_magic heap_version heap_ext_files heap_nrecs \
544	    heap_pagesize heap_pagecnt heap_nregions heap_regionsize flags ]
545
546	set btree_doc_list [list bt_magic bt_version bt_nkeys bt_ndata \
547	    bt_ext_files bt_pagecnt bt_pagesize bt_minkey bt_re_len bt_re_pad \
548	    bt_levels bt_int_pg bt_leaf_pg bt_dup_pg bt_over_pg bt_empty_pg \
549	    bt_free  bt_int_pgfree bt_leaf_pgfree bt_dup_pgfree \
550	    bt_over_pgfree flags ]
551
552	set queue_doc_list [list qs_magic qs_version qs_nkeys qs_ndata \
553	    qs_pagesize qs_extentsize qs_pages qs_re_len qs_re_pad qs_pgfree \
554	    qs_first_recno qs_cur_recno flags ]
555
556	# Check the hash db stat field.
557	puts "\tEnv017: Check the hash db stat"
558	env017_dbstat_check \
559	    $hash_map_list $hash_doc_list {hash_db_stat_check} {-create -hash}
560
561	# Check the heap db stat field.
562	puts "\tEnv017: Check the heap db stat"
563	env017_dbstat_check \
564	    $heap_map_list $heap_doc_list {heap_db_stat_check} {-create -heap}
565
566	# Check the queue db stat field.
567	puts "\tEnv017: Check the queue db stat"
568	env017_dbstat_check \
569	    $queue_map_list $queue_doc_list {queue_db_stat_check} \
570	    {-create -queue}
571
572	# Check the btree/recno db stat field.
573	puts "\tEnv017: Check the btree/recno db stat"
574	env017_dbstat_check \
575	    $btree_map_list $btree_doc_list {btree_db_stat_check} \
576	    {-create -btree}
577}
578
579
580# Check the sequence stat field.
581proc env017_seq_stat { } {
582	puts "\nEnv017: Check the sequence stat field"
583	source ./include.tcl
584	env_cleanup $testdir
585	set file1 db1.db
586	set db1 [berkdb open -create -btree $testdir/$file1]
587	error_check_good is_valid_db [is_valid_db $db1] TRUE
588	set seq [berkdb sequence -create -min 0 -max 1024768  $db1 seq_key1]
589	error_check_good is_valid_seq [is_valid_seq $seq] TRUE
590	set stat_list [$seq stat]
591	set map_list {
592		{ "Wait"	    st_wait }
593		{ "No wait"	    st_nowait }
594		{ "Current"	    st_current }
595		{ "Cached"	    st_value }
596		{ "Max Cached"	    st_last_value }
597		{ "Min"	    st_min }
598		{ "Max"	    st_max }
599		{ "Cache size"	    st_cache_size}
600		{ "Flags"	    st_flags}
601	}
602	set doc_list [list st_wait st_nowait st_current st_value \
603	    st_last_value st_min st_max st_cache_size st_flags]
604	env017_do_check $map_list $stat_list $doc_list {seq_stat}
605	set stat_list_clear [$seq stat -clear]
606	env017_do_check $map_list $stat_list_clear $doc_list {seq_stat}
607	set stat_list_all [$seq stat -all]
608	env017_do_check $map_list $stat_list_all $doc_list {seq_stat}
609	error_check_good "$seq close" [$seq close] 0
610	error_check_good "$db1 close" [$db1 close] 0
611}
612
613# Check the compact stat field.
614proc env017_compact_stat { } {
615	puts "\nEnv017: Check the compact stat field"
616	source ./include.tcl
617	env_cleanup $testdir
618	set file1 db1.db
619	set db1 [berkdb open -create -btree $testdir/$file1]
620	error_check_good is_valid_db [is_valid_db $db1] TRUE
621	set ret [catch {eval $db1 compact -freespace}]
622	error_check_good compact_ok $ret 0
623	set stat_list [$db1 compact_stat]
624	set map_list {
625		{ "Pages freed"		    compact_pages_free }
626		{ "Pages truncated"	    compact_pages_truncated }
627		{ "Pages examined"	    compact_pages_examine }
628		{ "Levels removed"	    compact_levels }
629		{ "Deadlocks encountered"   compact_deadlock }
630		{ "Empty buckets"		    compact_empty_buckets }
631	}
632	set doc_list [list compact_pages_free compact_pages_truncated \
633	    compact_pages_examine compact_levels compact_deadlock \
634	    compact_empty_buckets]
635	env017_do_check $map_list $stat_list $doc_list {compact_stat}
636	error_check_good "$db1 close" [$db1 close] 0
637}
638
639# This is common proc for the stat method called by env handle.
640proc env017_stat_check { map_list doc_list check_type stat_method \
641     {envargs {}} } {
642	source ./include.tcl
643	set extopts {
644		{""}
645		{"-thread"}
646		{"-private" {"mutex_stat" "requires.*mutex.*subsystem"}}
647		{"-thread -private"}
648	}
649
650	foreach extopt $extopts {
651		set extarg [lindex $extopt 0]
652		set failmsg ""
653		set fail 0
654		if {[llength $extopt] > 1} {
655			set len [llength $extopt]
656			for {set i 1} {$i < $len} {incr i} {
657				set item [lindex $extopt $i]
658				set stat [lindex $item 0]
659				if {$stat == $stat_method} {
660					set failmsg [lindex $item 1]
661					set fail 1
662					break
663				}
664			}
665		}
666
667		env_cleanup $testdir
668		puts "\tEnv017: Check DB_ENV->$stat_method ($envargs $extarg)"
669		set env [eval berkdb_env_noerr $extarg $envargs -home $testdir]
670		error_check_good is_valid_env [is_valid_env $env] TRUE
671		if {$fail == 0} {
672			set stat_list [$env $stat_method]
673			env017_do_check \
674			    $map_list $stat_list $doc_list $check_type
675		} else {
676			set ret [catch {eval $env $stat_method} res]
677			error_check_bad $stat_method $ret 0
678			error_check_bad chk_err [regexp $failmsg $res] 0
679		}
680		error_check_good "$env close" [$env close] 0
681	}
682}
683
684# This is a proc for the mpool stat method called by env handle.
685proc env017_mpstat_check { gsp_map_list fsp_map_list gsp_doc_list fsp_doc_list \
686    check_type stat_method {envargs {}} } {
687	source ./include.tcl
688	set extopts {
689		{""}
690		{"-thread"}
691		{"-private" {"mutex_stat" "requires.*mutex.*subsystem"}}
692		{"-thread -private"}
693	}
694
695	foreach extopt $extopts {
696		set extarg [lindex $extopt 0]
697		set failmsg ""
698		set fail 0
699		if {[llength $extopt] > 1} {
700			set len [llength $extopt]
701			for {set i 1} {$i < $len} {incr i} {
702				set item [lindex $extopt $i]
703				set stat [lindex $item 0]
704				if {$stat == $stat_method} {
705					set failmsg [lindex $item 1]
706					set fail 1
707					break
708				}
709			}
710		}
711
712		env_cleanup $testdir
713		puts "\tEnv017: Check DB_ENV->$stat_method ($envargs $extarg)"
714		set env [eval berkdb_env_noerr $extarg $envargs -home $testdir]
715		error_check_good is_valid_env [is_valid_env $env] TRUE
716		set mpools \
717		    [$env mpool -create -pagesize 65536 -mode 0644 mpool_file]
718		if {$fail == 0} {
719			set stat_list [$env $stat_method]
720			set stat_len [llength $stat_list]
721			set gsp_stat_list [lrange $stat_list 0 [expr $stat_len -2]]
722			set fsp_stat_list [lindex $stat_list [expr $stat_len -1]]
723			env017_do_check \
724			    $gsp_map_list $gsp_stat_list $gsp_doc_list $check_type
725			env017_do_check \
726			    $fsp_map_list $fsp_stat_list $fsp_doc_list $check_type
727		} else {
728			set ret [catch {eval $env $stat_method} res]
729			error_check_bad $stat_method $ret 0
730			error_check_bad chk_err [regexp $failmsg $res] 0
731		}
732		error_check_good "$env close" [$env close] 0
733	}
734}
735
736# This is common proc for db stat.
737proc env017_dbstat_check { map_list doc_list check_type {dbargs {}} } {
738	source ./include.tcl
739	env_cleanup $testdir
740	set filename "db1.db"
741	set db [eval berkdb_open_noerr $dbargs $testdir/$filename]
742	error_check_good is_valid_db [is_valid_db $db] TRUE
743	set stat_list [$db stat]
744	env017_do_check $map_list $stat_list $doc_list $check_type
745	error_check_good "$db close" [$db close] 0
746}
747
748# This proc does the actual checking job.
749proc env017_do_check { map_list stat_list doc_list check_type } {
750	# Check if all the items in the stat_list have the corresponding
751	# item in doc_list.
752	foreach l $map_list {
753		set field_map([lindex $l 0]) [lindex $l 1]
754	}
755	puts "\tEnv017: Check from stat_list"
756	set res_stat_list {}
757	foreach item $stat_list {
758		puts "\t\tEnv017: Checking item [lindex $item 0]"
759		if {![info exists field_map([lindex $item 0])]} {
760			lappend res_stat_list [lindex $item 0]
761			continue
762		}
763		set cur_field $field_map([lindex $item 0])
764		if {[lsearch -exact $doc_list $cur_field] == -1} {
765			lappend res_stat_list [lindex $item 0]
766		}
767	}
768	if {[llength $res_stat_list]>0} {
769		puts -nonewline "FAIL: in stat_list of $check_type, "
770		puts "Mismatch Items: $res_stat_list"
771	}
772
773	# Check if all the items in the doc_list have the corresponding
774	# record in the stat_list.
775	foreach l $map_list {
776		set field_map([lindex $l 1]) [lindex $l 0]
777	}
778
779	set stat_field_list {}
780
781	foreach item $stat_list {
782		lappend stat_field_list [lindex $item 0]
783	}
784
785	set res_doc_list {}
786	puts "\tEnv017: Check from doc_list"
787	foreach item $doc_list {
788		puts "\t\tEnv017: Checking item [lindex $item 0]"
789		if {![info exists field_map([lindex $item 0])]} {
790			lappend res_doc_list [lindex $item 0]
791			continue
792		}
793		set cur_field $field_map([lindex $item 0])
794		if {[lsearch -exact $stat_field_list $cur_field] == -1} {
795			lappend res_doc_list [lindex $item 0]
796		}
797	}
798	if {[llength $res_doc_list]>0} {
799		puts -nonewline "FAIL: in doc_list of $check_type, "
800		puts "Mismatch Items: $res_doc_list"
801	}
802}
803
804