Free iodevice memory when observer exit

This commit is contained in:
JiahuaChen
2023-05-25 17:11:17 +00:00
committed by ob-robot
parent e1e0ebaeb6
commit a66f2f136f
2 changed files with 18 additions and 13 deletions

View File

@ -62,18 +62,23 @@ int ObDeviceManager::init_devices_env()
void ObDeviceManager::destroy() void ObDeviceManager::destroy()
{ {
int ret_dev = OB_SUCCESS; int ret_dev = OB_SUCCESS;
int ret_handle = OB_SUCCESS; int ret_handle = OB_SUCCESS;
/*destroy fun wil release all the node*/ /*destroy fun wil release all the node*/
if (is_init_) { if (is_init_) {
ret_dev = device_map_.destroy(); ret_dev = device_map_.destroy();
ret_handle = handle_map_.destroy(); ret_handle = handle_map_.destroy();
allocator_.~ObFIFOAllocator();
if (OB_SUCCESS != ret_dev || OB_SUCCESS != ret_handle) { if (OB_SUCCESS != ret_dev || OB_SUCCESS != ret_handle) {
OB_LOG_RET(WARN, ret_dev, "fail to destroy device map", K(ret_dev), K(ret_handle)); OB_LOG_RET(WARN, ret_dev, "fail to destroy device map", K(ret_dev), K(ret_handle));
} }
//free the arena for (int i = 0; i < MAX_DEVICE_INSTANCE; i++ ) {
ObIODevice* del_device = device_ins_[i].device_;
if (OB_NOT_NULL(del_device)) {
del_device->destroy();
allocator_.free(del_device);
}
device_ins_[i].device_ = NULL;
}
allocator_.reset(); allocator_.reset();
fin_oss_env(); fin_oss_env();
is_init_ = false; is_init_ = false;

View File

@ -24,43 +24,43 @@ namespace common
class ObDeviceManager class ObDeviceManager
{ {
public: public:
const static int MAX_DEVICE_INSTANCE = 20; const static int MAX_DEVICE_INSTANCE = 20;
int init_devices_env(); int init_devices_env();
void destroy(); void destroy();
static ObDeviceManager &get_instance(); static ObDeviceManager &get_instance();
/*for object device, will return a new object to caller*/ /*for object device, will return a new object to caller*/
/*ofs/local will share in upper logical*/ /*ofs/local will share in upper logical*/
int get_device(const common::ObString& storage_info, int get_device(const common::ObString& storage_info,
const common::ObString& storage_type_prefix, const common::ObString& storage_type_prefix,
ObIODevice*& device_handle); ObIODevice*& device_handle);
int release_device(common::ObIODevice*& device_handle); int release_device(common::ObIODevice*& device_handle);
//for test //for test
int64_t get_device_cnt() {return device_count_;} int64_t get_device_cnt() {return device_count_;}
private: private:
ObDeviceManager(); ObDeviceManager();
~ObDeviceManager() {} ~ObDeviceManager() { destroy(); }
struct ObDeviceInsInfo { struct ObDeviceInsInfo {
ObIODevice* device_; ObIODevice* device_;
char storage_info_[OB_MAX_URI_LENGTH]; char storage_info_[OB_MAX_URI_LENGTH];
int64_t ref_cnt_; int64_t ref_cnt_;
}; };
/*notice: /*notice:
int the implement of hashtable, use the assign fun of class to copy key/value int the implement of hashtable, use the assign fun of class to copy key/value
but for string, assign fun just copy the pointer, so in device manager, should manager but for string, assign fun just copy the pointer, so in device manager, should manager
key mem space, in case upper lever release the pointer. key mem space, in case upper lever release the pointer.
*/ */
typedef common::hash::ObHashMap<ObString, ObDeviceInsInfo*> StoragInfoDeviceInfoMap; typedef common::hash::ObHashMap<ObString, ObDeviceInsInfo*> StoragInfoDeviceInfoMap;
typedef common::hash::ObHashMap<int64_t, ObDeviceInsInfo*> DeviceHandleDeviceInfoMap; typedef common::hash::ObHashMap<int64_t, ObDeviceInsInfo*> DeviceHandleDeviceInfoMap;
int alloc_device(ObDeviceInsInfo*& device_info, int alloc_device(ObDeviceInsInfo*& device_info,
const common::ObString& storage_info, const common::ObString& storage_info,
const common::ObString& storage_type_prefix); const common::ObString& storage_type_prefix);
common::ObFIFOAllocator allocator_; /*alloc/free dynamic device mem*/ common::ObFIFOAllocator allocator_; /*alloc/free dynamic device mem*/
int32_t device_count_; int32_t device_count_;
common::ObSpinLock lock_; /*the manager is global used, so need lock to guarante thread safe*/ common::ObSpinLock lock_; /*the manager is global used, so need lock to guarante thread safe*/