/* * is_class () - check if an object is a class * * return : bool * obj_oid - the oid of the object * class_oid - the class oid of obj_oid * */ static bool is_class (OID * obj_oid, OID * class_oid) { if (OID_EQ (class_oid, oid_Root_class_oid)) { return true; } return false; }
/* * orp_ht_comparef - * return: * key1(): * key2(): * r(): */ static int orp_ht_comparef (void *key1, void *key2, int *r) { OID *oid1 = (OID *) key1; OID *oid2 = (OID *) key2; assert (oid1 != NULL); assert (oid2 != NULL); *r = OID_EQ (oid1, oid2) ? 0 : OID_GT (oid1, oid2) ? 1 : -1; return NO_ERROR; }
/* * find_oid - search an oid in a list of oids * return: the index of the oid on success, -1 otherwise * oid(in): the searched oid * oids_list(in): the list where oid is searched * num_class_mops(in): the length of oids_list */ static int find_oid (OID * oid, OID ** oids_list, int num_oids) { int i; if (oid == NULL || oids_list == NULL || num_oids <= 0) { return -1; } for (i = 0; i < num_oids; i++) { if (oids_list[i] == NULL) { continue; } if (OID_EQ (oid, oids_list[i])) { return i; } } return -1; }
/* * boot_compact_db - compact specified classes * HEAP_CACHE_ATTRINFO structure * return: error status * class_oids(in): the classes list * n_classes(in): the class_oids length * hfids(in): the hfid list * space_to_process(in): the space to process * instance_lock_timeout(in): the lock timeout for instances * class_lock_timeout(in): the lock timeout for instances * delete_old_repr(in): whether to delete the old class representation * last_processed_class_oid(in,out): last processed class oid * last_processed_oid(in,out): last processed oid * total_objects(out): count processed objects for each class * failed_objects(out): count failed objects for each class * modified_objects(out): count modified objects for each class * big_objects(out): count big objects for each class * initial_last_repr_id(in, out): the list of initial last class * representation */ int boot_compact_db (THREAD_ENTRY * thread_p, OID * class_oids, int n_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 *initial_last_repr_id) { int result = NO_ERROR; int i, j, start_index = -1; int max_space_to_process, current_tran_index = -1; int lock_ret; HFID hfid; if (boot_can_compact (thread_p) == false) { return ER_COMPACTDB_ALREADY_STARTED; } if (class_oids == NULL || n_classes <= 0 || space_to_process <= 0 || last_processed_class_oid == NULL || last_processed_oid == NULL || total_objects == NULL || failed_objects == NULL || modified_objects == NULL || big_objects == NULL || initial_last_repr_id == NULL) { return ER_QPROC_INVALID_PARAMETER; } for (start_index = 0; start_index < n_classes; start_index++) { if (OID_EQ (class_oids + start_index, last_processed_class_oid)) { break; } } if (start_index == n_classes) { return ER_QPROC_INVALID_PARAMETER; } for (i = 0; i < n_classes; i++) { total_objects[i] = 0; failed_objects[i] = 0; modified_objects[i] = 0; big_objects[i] = 0; } max_space_to_process = space_to_process; for (i = start_index; i < n_classes; i++) { lock_ret = lock_object_waitsecs (thread_p, class_oids + i, oid_Root_class_oid, IX_LOCK, LK_UNCOND_LOCK, class_lock_timeout); if (lock_ret != LK_GRANTED) { total_objects[i] = COMPACTDB_LOCKED_CLASS; OID_SET_NULL (last_processed_oid); continue; } if (heap_get_hfid_from_class_oid (thread_p, class_oids + i, &hfid) != NO_ERROR) { lock_unlock_object (thread_p, class_oids + i, oid_Root_class_oid, IX_LOCK, true); OID_SET_NULL (last_processed_oid); total_objects[i] = COMPACTDB_INVALID_CLASS; continue; } if (HFID_IS_NULL (&hfid)) { lock_unlock_object (thread_p, class_oids + i, oid_Root_class_oid, IX_LOCK, true); OID_SET_NULL (last_processed_oid); total_objects[i] = COMPACTDB_INVALID_CLASS; continue; } if (OID_ISNULL (last_processed_oid)) { initial_last_repr_id[i] = heap_get_class_repr_id (thread_p, class_oids + i); if (initial_last_repr_id[i] <= 0) { lock_unlock_object (thread_p, class_oids + i, oid_Root_class_oid, IX_LOCK, true); total_objects[i] = COMPACTDB_INVALID_CLASS; continue; } } if (process_class (thread_p, class_oids + i, &hfid, max_space_to_process, &instance_lock_timeout, &space_to_process, last_processed_oid, total_objects + i, failed_objects + i, modified_objects + i, big_objects + i) != NO_ERROR) { OID_SET_NULL (last_processed_oid); for (j = start_index; j <= i; j++) { total_objects[j] = COMPACTDB_UNPROCESSED_CLASS; failed_objects[j] = 0; modified_objects[j] = 0; big_objects[j] = 0; } result = ER_FAILED; break; } if (delete_old_repr && OID_ISNULL (last_processed_oid) && failed_objects[i] == 0 && heap_get_class_repr_id (thread_p, class_oids + i) == initial_last_repr_id[i]) { lock_ret = lock_object_waitsecs (thread_p, class_oids + i, oid_Root_class_oid, X_LOCK, LK_UNCOND_LOCK, class_lock_timeout); if (lock_ret == LK_GRANTED) { if (catalog_drop_old_representations (thread_p, class_oids + i) != NO_ERROR) { for (j = start_index; j <= i; j++) { total_objects[j] = COMPACTDB_UNPROCESSED_CLASS; failed_objects[j] = 0; modified_objects[j] = 0; big_objects[j] = 0; } result = ER_FAILED; } else { initial_last_repr_id[i] = COMPACTDB_REPR_DELETED; } break; } } if (space_to_process == 0) { break; } } if (OID_ISNULL (last_processed_oid)) { if (i < n_classes - 1) { COPY_OID (last_processed_class_oid, class_oids + i + 1); } else { OID_SET_NULL (last_processed_class_oid); } } else { COPY_OID (last_processed_class_oid, class_oids + i); } return result; }