8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 09:23:09 +01:00
firebird-mirror/src/jrd/validation.h

165 lines
4.0 KiB
C
Raw Normal View History

/*
* PROGRAM: JRD Access Method
* MODULE: validation.h
* DESCRIPTION: Validation and garbage collection
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef JRD_VALIDATION_H
#define JRD_VALIDATION_H
#include "firebird.h"
#include "fb_types.h"
#include "../jrd/ods.h"
#include "../jrd/sbm.h"
#include "../jrd/RecordNumber.h"
namespace Jrd
{
class Attachment;
class Database;
class jrd_rel;
class thread_db;
// Validation/garbage collection/repair control block
class Validation
{
private:
enum FETCH_CODE
{
fetch_ok,
//fetch_checksum,
fetch_type,
fetch_duplicate
};
enum RTN
{
rtn_ok,
rtn_corrupt,
rtn_eof
};
enum VAL_ERRORS
{
VAL_PAG_WRONG_TYPE = 0,
VAL_PAG_CHECKSUM_ERR = 1,
VAL_PAG_DOUBLE_ALLOC = 2,
VAL_PAG_IN_USE = 3,
VAL_PAG_ORPHAN = 4,
VAL_BLOB_INCONSISTENT = 5,
VAL_BLOB_CORRUPT = 6,
VAL_BLOB_TRUNCATED = 7,
VAL_REC_CHAIN_BROKEN = 8,
VAL_DATA_PAGE_CONFUSED = 9,
VAL_DATA_PAGE_LINE_ERR = 10,
VAL_INDEX_PAGE_CORRUPT = 11,
VAL_P_PAGE_LOST = 12,
VAL_P_PAGE_INCONSISTENT = 13,
VAL_REC_DAMAGED = 14,
VAL_REC_BAD_TID = 15,
VAL_REC_FRAGMENT_CORRUPT = 16,
VAL_REC_WRONG_LENGTH = 17,
VAL_INDEX_ROOT_MISSING = 18,
VAL_TIP_LOST = 19,
VAL_TIP_LOST_SEQUENCE = 20,
VAL_TIP_CONFUSED = 21,
VAL_REL_CHAIN_ORPHANS = 22,
VAL_INDEX_MISSING_ROWS = 23,
VAL_INDEX_ORPHAN_CHILD = 24,
VAL_INDEX_CYCLE = 25,
VAL_SCNS_PAGE_INCONSISTENT = 26,
VAL_PAG_WRONG_SCN = 27,
VAL_BLOB_UNKNOWN_LEVEL = 28,
VAL_INDEX_BAD_LEFT_SIBLING = 29,
VAL_INDEX_MISSES_NODE = 30,
VAL_PIP_WRONG_MIN = 31,
VAL_PIP_WRONG_EXTENT = 32,
VAL_PIP_WRONG_USED = 33,
VAL_P_PAGE_WRONG_BITS = 34,
VAL_MAX_ERROR = 35
};
struct MSG_ENTRY
{
bool error;
UCHAR info_item;
TEXT* msg;
};
static const MSG_ENTRY vdr_msg_table[VAL_MAX_ERROR];
// vdr_flags
static const USHORT VDR_update = 2; // fix simple things
static const USHORT VDR_repair = 4; // fix non-simple things (-mend)
static const USHORT VDR_records = 8; // Walk all records
thread_db* vdr_tdbb;
ULONG vdr_max_page;
USHORT vdr_flags;
USHORT vdr_errors;
TraNumber vdr_max_transaction;
FB_UINT64 vdr_rel_backversion_counter; // Counts slots w/rhd_chain
FB_UINT64 vdr_rel_chain_counter; // Counts chains w/rdr_chain
RecordBitmap* vdr_rel_records; // 1 bit per valid record
RecordBitmap* vdr_idx_records; // 1 bit per index item
PageBitmap* vdr_page_bitmap;
ULONG vdr_err_counts[VAL_MAX_ERROR];
public:
Validation();
~Validation() {};
bool run(thread_db* tdbb, USHORT switches);
ULONG getInfo(UCHAR item);
private:
void cleanup();
RTN corrupt(int, const jrd_rel*, ...);
FETCH_CODE fetch_page(bool validate, ULONG, USHORT, WIN*, void*);
void garbage_collect();
RTN walk_blob(jrd_rel*, const Ods::blh*, USHORT, RecordNumber);
RTN walk_chain(jrd_rel*, const Ods::rhd*, RecordNumber);
RTN walk_data_page(jrd_rel*, ULONG, ULONG, UCHAR&);
void walk_database();
void walk_generators();
void walk_header(ULONG);
RTN walk_index(jrd_rel*, Ods::index_root_page&, USHORT);
void walk_pip();
RTN walk_pointer_page(jrd_rel*, ULONG);
RTN walk_record(jrd_rel*, const Ods::rhd*, USHORT, RecordNumber, bool);
RTN walk_relation(jrd_rel*);
RTN walk_root(jrd_rel*);
RTN walk_scns();
RTN walk_tip(TraNumber);
};
} // namespace Jrd
#endif