45 #define COMPACT_MIN_PAGES 1 46 #define COMPACT_MAX_PAGES 20 48 #define COMPACT_INSTANCE_MIN_LOCK_TIMEOUT 1 49 #define COMPACT_INSTANCE_MAX_LOCK_TIMEOUT 10 51 #define COMPACT_CLASS_MIN_LOCK_TIMEOUT 1 52 #define COMPACT_CLASS_MAX_LOCK_TIMEOUT 10 56 int *
const num_classes_fully_processed,
const bool verbose,
57 const int class_lock_timeout);
59 bool *
const correctly_processed,
bool *
const addresses_reclaimed,
60 int *
const error_while_processing);
62 bool *
const any_class_can_be_referenced,
MOP *
const all_mops,
65 bool *
const class_can_be_referenced,
bool *
const any_class_can_be_referenced);
67 bool *
const class_can_be_referenced,
68 bool *
const any_class_can_be_referenced);
70 bool *
const class_can_be_referenced,
bool *
const any_class_can_be_referenced);
71 extern int get_class_mops (
char **class_names,
int num_class,
MOP ** class_list,
int *num_class_list);
83 const char *exec_name;
85 exec_name =
basename ((
char *) argv0);
101 if (oid ==
NULL || oids_list ==
NULL || num_oids <= 0)
106 for (i = 0; i < num_oids; i++)
108 if (oids_list[i] ==
NULL)
113 if (
OID_EQ (oid, oids_list[i]))
138 int failed_objects,
int modified_objects,
int big_objects,
bool delete_old_repr_flag,
139 bool old_repr_deleted)
142 char *temp_class_name;
145 if (class_mop ==
NULL)
152 if (temp_class_name ==
NULL ||
strlen (temp_class_name) == 0)
168 if (!processed_class)
189 if (delete_old_repr_flag)
191 if (old_repr_deleted)
211 char *temp_class_name;
220 if (class_mop ==
NULL)
226 if (temp_class_name ==
NULL)
231 result = (
char *) malloc (
sizeof (
char) * (
strlen (temp_class_name) + 1));
237 strcpy (result, temp_class_name);
254 int input_class_length,
int max_processed_space,
int instance_lock_timeout,
int class_lock_timeout,
259 int i, num_classes = 0;
261 OID last_processed_class_oid, last_processed_oid;
264 int *modified_objects =
NULL, *iteration_modified_objects =
NULL;
265 char *incomplete_processing =
NULL;
266 int *big_objects =
NULL, *iteration_big_objects =
NULL;
267 int *initial_last_repr =
NULL;
269 int last_completed_class_index, temp_index;
270 int num_class_mops = 0;
272 int num_classes_fully_compacted = 0;
273 char *class_name =
NULL;
274 MOP *processed_class_mops =
NULL;
276 if (input_filename && input_class_names && input_class_length > 0)
294 if (input_class_names && input_class_length > 0)
296 status =
get_class_mops (input_class_names, input_class_length, &class_mops, &num_class_mops);
302 else if (input_filename)
319 class_mops = class_table->
mops;
320 num_class_mops = class_table->
num;
324 if (class_oids ==
NULL)
330 for (i = 0; i < num_class_mops; i++)
332 class_oids[
i] =
NULL;
336 if (processed_class_mops ==
NULL)
342 for (i = 0; i < num_class_mops; i++)
344 processed_class_mops[
i] =
NULL;
348 for (i = 0; i < num_class_mops; i++)
351 if (class_ptr ==
NULL)
361 class_oids[num_classes] =
ws_oid (class_mops[i]);
362 if (class_oids[num_classes] !=
NULL)
364 processed_class_mops[num_classes] = class_mops[
i];
369 if (num_classes == 0)
375 total_objects = (
int *) malloc (num_classes *
sizeof (
int));
376 if (total_objects ==
NULL)
382 iteration_total_objects = (
int *) malloc (num_classes *
sizeof (
int));
383 if (iteration_total_objects ==
NULL)
389 failed_objects = (
int *) malloc (num_classes *
sizeof (
int));
390 if (failed_objects ==
NULL)
396 iteration_failed_objects = (
int *) malloc (num_classes *
sizeof (
int));
397 if (iteration_failed_objects ==
NULL)
403 modified_objects = (
int *) malloc (num_classes *
sizeof (
int));
404 if (modified_objects ==
NULL)
410 iteration_modified_objects = (
int *) malloc (num_classes *
sizeof (
int));
411 if (iteration_modified_objects ==
NULL)
417 big_objects = (
int *) malloc (num_classes *
sizeof (
int));
418 if (big_objects ==
NULL)
424 iteration_big_objects = (
int *) malloc (num_classes *
sizeof (
int));
425 if (iteration_big_objects ==
NULL)
431 initial_last_repr = (
int *) malloc (num_classes *
sizeof (
int));
432 if (initial_last_repr ==
NULL)
438 incomplete_processing = (
char *) malloc (num_classes *
sizeof (
char));
439 if (incomplete_processing ==
NULL)
445 for (i = 0; i < num_classes; i++)
447 total_objects[
i] = 0;
448 failed_objects[
i] = 0;
449 modified_objects[
i] = 0;
451 incomplete_processing[
i] = 0;
455 for (i = 0; i < num_class_mops; i++)
470 COPY_OID (&last_processed_class_oid, class_oids[0]);
473 last_completed_class_index = -1;
496 boot_compact_classes (class_oids, num_classes, max_processed_space, instance_lock_timeout, class_lock_timeout,
497 delete_old_repr_flag, &last_processed_class_oid, &last_processed_oid,
498 iteration_total_objects, iteration_failed_objects, iteration_modified_objects,
499 iteration_big_objects, initial_last_repr);
503 temp_index = num_classes;
507 temp_index =
find_oid (&last_processed_class_oid, class_oids, num_classes);
513 if (delete_old_repr_flag && temp_index - 1 > last_completed_class_index)
515 for (i = last_completed_class_index + 1; i < temp_index; i++)
553 for (i = 0; i < num_classes; i++)
555 if (iteration_total_objects[i] >= 0)
557 total_objects[
i] += iteration_total_objects[
i];
558 failed_objects[
i] += iteration_failed_objects[
i];
559 modified_objects[
i] += iteration_modified_objects[
i];
560 big_objects[
i] += iteration_big_objects[
i];
564 incomplete_processing[
i] = iteration_total_objects[
i];
568 if (temp_index - 1 > last_completed_class_index)
570 for (i = last_completed_class_index + 1; i < temp_index; i++)
590 failed_objects[i], modified_objects[i], big_objects[i], delete_old_repr_flag,
596 last_completed_class_index = temp_index - 1;
609 status =
do_reclaim_addresses (class_oids, num_classes, &num_classes_fully_compacted, verbose_flag,
621 for (i = 0; i < num_classes; i++)
667 if (class_name ==
NULL)
701 if (processed_class_mops)
711 if (iteration_total_objects)
721 if (iteration_failed_objects)
726 if (modified_objects)
731 if (iteration_modified_objects)
741 if (iteration_big_objects)
746 if (initial_last_repr)
751 if (incomplete_processing)
764 for (i = 0; i < num_class_mops; i++)
766 class_mops[
i] =
NULL;
791 bool verbose_flag = 0, delete_old_repr_flag = 0, standby_compactdb_flag = 0;
793 int maximum_processed_space = 10 *
DB_PAGESIZE, pages;
794 int instance_lock_timeout, class_lock_timeout;
795 char **tables =
NULL;
821 if (table_size > 1 && input_filename !=
NULL)
849 COMPACT_CLASS_MAX_LOCK_TIMEOUT);
860 tables = (
char **) malloc (
sizeof (
char *) * (table_size - 1));
868 for (i = 1; i < table_size; i++)
878 if (standby_compactdb_flag)
898 if (class_lock_timeout > 0)
900 class_lock_timeout = class_lock_timeout * 1000;
902 if (instance_lock_timeout > 0)
904 instance_lock_timeout = instance_lock_timeout * 1000;
907 compactdb_start (verbose_flag, delete_old_repr_flag, input_filename, tables, table_size - 1,
908 maximum_processed_space, instance_lock_timeout, class_lock_timeout,
931 const bool verbose,
const int class_lock_timeout)
933 bool any_class_can_be_referenced =
false;
937 assert (num_class_oids >= 0);
941 *num_classes_fully_processed = 0;
945 for (i = 0; i < num_class_oids; ++
i)
947 char *class_name =
NULL;
948 int error_while_processing =
NO_ERROR;
949 bool correctly_processed =
false;
950 bool addresses_reclaimed =
false;
954 &addresses_reclaimed, &error_while_processing);
955 if (correctly_processed)
959 (*num_classes_fully_processed)++;
964 if (class_name ==
NULL ||
strlen (class_name) == 0)
974 if (correctly_processed)
976 if (addresses_reclaimed)
992 if (class_name !=
NULL)
1016 bool *
const correctly_processed,
bool *
const addresses_reclaimed,
1017 int *
const error_while_processing)
1025 bool do_abort_on_error =
true;
1026 bool can_reclaim_addresses =
true;
1032 assert (any_class_can_be_referenced !=
NULL);
1038 *correctly_processed =
false;
1039 *addresses_reclaimed =
false;
1040 *error_while_processing =
NO_ERROR;
1065 if (class_mop ==
NULL)
1097 if (*class_name ==
NULL)
1103 if (class_->partition !=
NULL)
1112 if (skipped_error_code !=
NO_ERROR)
1116 if (parent_mop !=
NULL)
1119 if (parent_class_ ==
NULL)
1129 if (skipped_error_code !=
NO_ERROR)
1136 can_reclaim_addresses =
false;
1143 can_reclaim_addresses =
false;
1156 can_reclaim_addresses =
false;
1164 can_reclaim_addresses =
true;
1168 if (*any_class_can_be_referenced)
1175 can_reclaim_addresses =
false;
1179 bool class_can_be_referenced =
false;
1195 skipped_error_code =
1197 any_class_can_be_referenced, lmops->
mops, lmops->
num);
1198 if (skipped_error_code !=
NO_ERROR)
1208 can_reclaim_addresses = !class_can_be_referenced && !*any_class_can_be_referenced;
1224 if (can_reclaim_addresses)
1229 if (skipped_error_code !=
NO_ERROR)
1233 *addresses_reclaimed =
true;
1243 *correctly_processed =
true;
1247 parent_class_ =
NULL;
1251 *error_while_processing = skipped_error_code;
1255 parent_class_ =
NULL;
1261 if (do_abort_on_error)
1277 error_code = tmp_error_code;
1290 bool *
const any_class_can_be_referenced,
MOP *
const all_mops,
const int num_mops)
1297 assert (any_class_can_be_referenced !=
NULL);
1301 *class_can_be_referenced =
false;
1303 for (i = 0; i < num_mops; ++
i)
1311 if (*any_class_can_be_referenced)
1325 bool *
const any_class_can_be_referenced)
1332 if (referring_class ==
NULL)
1348 attributes_list = referring_class->
attributes;
1353 any_class_can_be_referenced);
1358 if (*any_class_can_be_referenced)
1374 any_class_can_be_referenced);
1379 if (*any_class_can_be_referenced)
1384 attributes_list = referring_class->
shared;
1387 any_class_can_be_referenced);
1392 if (*any_class_can_be_referenced)
1410 bool *
const class_can_be_referenced,
bool *
const any_class_can_be_referenced)
1417 any_class_can_be_referenced);
1418 if (*any_class_can_be_referenced)
1422 if (parent_mop !=
NULL)
1425 any_class_can_be_referenced);
1426 if (*any_class_can_be_referenced)
1439 bool *
const any_class_can_be_referenced)
1445 for (crt_domain = domain; crt_domain !=
NULL; crt_domain =
db_domain_next (crt_domain))
1454 *any_class_can_be_referenced =
true;
1456 else if (referenced_class == class_ ||
db_is_subclass (referenced_class, class_) > 0)
1458 *class_can_be_referenced =
true;
1468 any_class_can_be_referenced);
1475 if (*any_class_can_be_referenced)
#define ER_LK_UNILATERALLY_ABORTED
int sm_destroy_representations(MOP op)
#define COMPACT_DELETE_OLD_REPR_S
static void show_statistics(OID *class_oid, bool unlocked_class, bool valid_class, bool processed_class, int total_objects, int failed_objects, int modified_objects, int big_objects, bool delete_old_repr_flag, bool old_repr_deleted)
#define COMPACTDB_INVALID_CLASS
void db_set_client_type(int client_type)
static char * get_name_from_class_oid(OID *class_oid)
#define PRINT_AND_LOG_ERR_MSG(...)
const char * db_get_class_name(DB_OBJECT *class_)
int sysprm_set_force(const char *pname, const char *pvalue)
#define COMPACT_CLASS_MAX_LOCK_TIMEOUT
int db_login(const char *name, const char *password)
DB_OBJECT * db_object(DB_IDENTIFIER *oid)
#define COMPACT_MIN_PAGES
#define AU_DISABLE_PASSWORDS
int compactdb(UTIL_FUNCTION_ARG *arg)
#define TRAN_DEFAULT_ISOLATION_LEVEL()
SM_ATTRIBUTE * attributes
DB_DOMAIN * db_domain_next(const DB_DOMAIN *domain)
struct sm_component * next
#define OID_SET_NULL(oidp)
int db_is_subclass(MOP classmop, MOP supermop)
int do_get_partition_parent(DB_OBJECT *const classop, MOP *const parentop)
int compact_db_start(void)
#define COMPACTDB_LOCKED_CLASS
void locator_free_list_mops(LIST_MOPS *mops)
LIST_MOPS * locator_get_all_mops(MOP class_mop, DB_FETCH_MODE purpose, LC_FETCH_VERSION_TYPE *force_fetch_version_type)
#define COMPACT_INSTANCE_MIN_LOCK_TIMEOUT
int util_log_write_errid(int message_id,...)
static void class_referenced_by_domain(MOP referenced_class, TP_DOMAIN *const domain, bool *const class_can_be_referenced, bool *const any_class_can_be_referenced)
#define COPY_OID(dest_oid_ptr, src_oid_ptr)
#define COMPACT_INSTANCE_MAX_LOCK_TIMEOUT
int utility_get_option_int_value(UTIL_ARG_MAP *arg_map, int arg_ch)
static int class_referenced_by_class(MOP referenced_mop, MOP parent_mop, MOP referring_mop, bool *const class_can_be_referenced, bool *const any_class_can_be_referenced)
static void compactdb_usage(const char *argv0)
static DB_OBJECT * is_class(OID *obj_oid, OID *class_oid)
int boot_heap_compact(OID *class_oid)
MOBJ locator_fetch_class(MOP class_mop, DB_FETCH_MODE purpose)
bool pr_is_set_type(DB_TYPE type)
#define COMPACT_MAX_PAGES
int tran_reset_wait_times(int wait_in_msecs)
int db_restart(const char *program, int print_version, const char *volume)
const char * sm_ch_name(const MOBJ clobj)
bool utility_get_option_bool_value(UTIL_ARG_MAP *arg_map, int arg_ch)
int heap_reclaim_addresses(const HFID *hfid)
SM_ATTRIBUTE * class_attributes
HFID * sm_ch_heap(MOBJ clobj)
const char * db_error_string(int level)
DB_OBJECT * db_domain_class(const DB_DOMAIN *domain)
#define COMPACT_STANDBY_CS_MODE_S
#define OID_EQ(oidp1, oidp2)
int db_abort_transaction(void)
#define TP_DOMAIN_TYPE(dom)
int tran_abort_only_client(bool is_server_down)
static int compactdb_start(bool verbose_flag, bool delete_old_repr_flag, char *input_filename, char **input_class_names, int input_class_length, int max_processed_space, int instance_lock_timeout, int class_lock_timeout, DB_TRAN_ISOLATION tran_isolation)
int get_class_mops(char **class_names, int num_class, MOP **class_list, int *num_class_list)
static int failed_objects
#define COMPACTDB_UNPROCESSED_CLASS
static int class_referenced_by_attributes(MOP referenced_class, MOP parent_mop, SM_ATTRIBUTE *const attributes_list, bool *const class_can_be_referenced, bool *const any_class_can_be_referenced)
#define COMPACT_CLASS_LOCK_TIMEOUT_S
int db_set_isolation(DB_TRAN_ISOLATION isolation)
static int do_reclaim_addresses(OID *const *class_oids, const int num_class_oids, int *const num_classes_fully_processed, const bool verbose, const int class_lock_timeout)
int utility_get_option_string_table_size(UTIL_ARG_MAP *arg_map)
#define COMPACT_CLASS_MIN_LOCK_TIMEOUT
LIST_MOPS * locator_get_all_class_mops(DB_FETCH_MODE purpose, int(*fun)(MOBJ class_obj))
static void error(const char *msg)
#define HFID_IS_NULL(hfid)
static char database_name[MAX_HA_DBINFO_LENGTH]
int compact_db_stop(void)
#define free_and_init(ptr)
char * basename(const char *path)
int locator_flush_all_instances(MOP class_mop, bool decache)
char * msgcat_message(int cat_id, int set_id, int msg_id)
const char * prm_get_name(PARAM_ID prm_id)
char * strdup(const char *str)
static int do_reclaim_class_addresses(const OID class_oid, char **clas_name, bool *const any_class_can_be_referenced, bool *const correctly_processed, bool *const addresses_reclaimed, int *const error_while_processing)
#define COMPACT_PAGES_COMMITED_ONCE_S
#define OPTION_STRING_TABLE
#define ER_COMPACTDB_ALREADY_STARTED
int locator_is_class(MOP mop, DB_FETCH_MODE hint_purpose)
#define COMPACT_INSTANCE_LOCK_TIMEOUT_S
#define COMPACT_INPUT_CLASS_FILE_S
#define COMPACTDB_REPR_DELETED
int ws_find(MOP mop, MOBJ *obj)
int boot_compact_classes(OID **class_oids, int num_classes, int space_to_process, int instance_lock_timeout, int class_lock_timeout, bool delete_old_repr, OID *last_processed_class_oid, OID *last_processed_oid, int *total_objects, int *failed_objects, int *modified_objects, int *big_objects, int *ids_repr)
static int find_oid(OID *oid, OID **oids_list, int num_oids)
const char * command_name
static int class_instances_can_be_referenced(MOP mop, MOP parent_mop, bool *const class_can_be_referenced, bool *const any_class_can_be_referenced, MOP *const all_mops, const int num_mops)
char * utility_get_option_string_value(UTIL_ARG_MAP *arg_map, int arg_ch, int index)
static int is_not_system_class(MOBJ class_)
DB_DOMAIN * db_domain_set(const DB_DOMAIN *domain)
int db_commit_transaction(void)
int get_class_mops_from_file(const char *input_filename, MOP **class_list, int *num_class_mops)
#define COMPACT_VERBOSE_S
#define MSGCAT_CATALOG_UTILS