[bugfix] add memtable array lock int table store
This commit is contained in:
@ -40,6 +40,8 @@ ObTabletTableStore::ObTabletTableStore()
|
|||||||
ddl_sstables_(),
|
ddl_sstables_(),
|
||||||
meta_major_tables_(),
|
meta_major_tables_(),
|
||||||
memtables_(),
|
memtables_(),
|
||||||
|
ddl_mem_sstables_(),
|
||||||
|
memtables_lock_(),
|
||||||
is_ready_for_read_(false),
|
is_ready_for_read_(false),
|
||||||
is_inited_(false)
|
is_inited_(false)
|
||||||
{
|
{
|
||||||
@ -867,6 +869,7 @@ int ObTabletTableStore::get_table(const ObITable::TableKey &table_key, ObITable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (table_key.is_memtable()) {
|
if (table_key.is_memtable()) {
|
||||||
|
common::SpinRLockGuard guard(memtables_lock_);
|
||||||
if (OB_FAIL(memtables_.find(table_key, table))) {
|
if (OB_FAIL(memtables_.find(table_key, table))) {
|
||||||
LOG_WARN("fail to get memtable", K(ret), K(table_key), K_(memtables));
|
LOG_WARN("fail to get memtable", K(ret), K(table_key), K_(memtables));
|
||||||
}
|
}
|
||||||
@ -895,7 +898,7 @@ int ObTabletTableStore::get_read_tables(
|
|||||||
const bool allow_no_ready_read) const
|
const bool allow_no_ready_read) const
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
|
common::SpinRLockGuard guard(memtables_lock_);
|
||||||
if (OB_UNLIKELY(snapshot_version < 0)) {
|
if (OB_UNLIKELY(snapshot_version < 0)) {
|
||||||
ret = OB_INVALID_ARGUMENT;
|
ret = OB_INVALID_ARGUMENT;
|
||||||
LOG_WARN("invalid argument", K(ret), K(snapshot_version));
|
LOG_WARN("invalid argument", K(ret), K(snapshot_version));
|
||||||
@ -973,6 +976,7 @@ int ObTabletTableStore::get_memtables(
|
|||||||
common::ObIArray<storage::ObITable *> &memtables,
|
common::ObIArray<storage::ObITable *> &memtables,
|
||||||
const bool need_active) const
|
const bool need_active) const
|
||||||
{
|
{
|
||||||
|
common::SpinRLockGuard guard(memtables_lock_);
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < memtables_.count(); ++i) {
|
for (int64_t i = 0; OB_SUCC(ret) && i < memtables_.count(); ++i) {
|
||||||
if (OB_ISNULL(memtables_[i])) {
|
if (OB_ISNULL(memtables_[i])) {
|
||||||
@ -990,6 +994,7 @@ int ObTabletTableStore::get_memtables(
|
|||||||
int ObTabletTableStore::update_memtables(const common::ObIArray<storage::ObITable *> &memtables)
|
int ObTabletTableStore::update_memtables(const common::ObIArray<storage::ObITable *> &memtables)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
|
common::SpinWLockGuard guard(memtables_lock_);
|
||||||
if (IS_NOT_INIT) {
|
if (IS_NOT_INIT) {
|
||||||
ret = OB_NOT_INIT;
|
ret = OB_NOT_INIT;
|
||||||
LOG_WARN("not init", K(ret));
|
LOG_WARN("not init", K(ret));
|
||||||
@ -1001,6 +1006,7 @@ int ObTabletTableStore::update_memtables(const common::ObIArray<storage::ObITabl
|
|||||||
|
|
||||||
int ObTabletTableStore::clear_memtables()
|
int ObTabletTableStore::clear_memtables()
|
||||||
{
|
{
|
||||||
|
common::SpinWLockGuard guard(memtables_lock_);
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
if (OB_UNLIKELY(!is_valid())) {
|
if (OB_UNLIKELY(!is_valid())) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
@ -1014,6 +1020,7 @@ int ObTabletTableStore::clear_memtables()
|
|||||||
int ObTabletTableStore::get_first_frozen_memtable(ObITable *&table) const
|
int ObTabletTableStore::get_first_frozen_memtable(ObITable *&table) const
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
|
common::SpinRLockGuard guard(memtables_lock_);
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < memtables_.count(); ++i) {
|
for (int64_t i = 0; OB_SUCC(ret) && i < memtables_.count(); ++i) {
|
||||||
if (OB_ISNULL(memtables_[i])) {
|
if (OB_ISNULL(memtables_[i])) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
|||||||
@ -323,6 +323,7 @@ private:
|
|||||||
ObSSTableArray meta_major_tables_;
|
ObSSTableArray meta_major_tables_;
|
||||||
ObMemtableArray memtables_;
|
ObMemtableArray memtables_;
|
||||||
ObDDLKVArray ddl_mem_sstables_;
|
ObDDLKVArray ddl_mem_sstables_;
|
||||||
|
mutable common::SpinRWLock memtables_lock_; // protect memtable read and update after inited
|
||||||
bool is_ready_for_read_;
|
bool is_ready_for_read_;
|
||||||
bool is_inited_;
|
bool is_inited_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user