trx.cpp 1.5 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Wangyunlai on 2021/5/24.
//

#include <atomic>

#include "storage/trx/trx.h"
#include "storage/common/table.h"
羽飞's avatar
羽飞 已提交
19
#include "storage/record/record_manager.h"
羽飞's avatar
羽飞 已提交
20 21
#include "storage/common/field_meta.h"
#include "common/log/log.h"
羽飞's avatar
羽飞 已提交
22 23 24
#include "storage/common/field.h"
#include "storage/trx/mvcc_trx.h"
#include "storage/trx/vacuous_trx.h"
羽飞's avatar
羽飞 已提交
25

羽飞's avatar
羽飞 已提交
26
static TrxKit *global_trxkit = nullptr;
羽飞's avatar
羽飞 已提交
27

羽飞's avatar
羽飞 已提交
28
TrxKit *TrxKit::create(const char *name)
29
{
羽飞's avatar
羽飞 已提交
30 31
  if (0 == strcasecmp(name, "mvcc")) {
    return new MvccTrxKit();
羽飞's avatar
羽飞 已提交
32
  }
羽飞's avatar
羽飞 已提交
33 34
  
  return new VacuousTrxKit();
羽飞's avatar
羽飞 已提交
35 36
}

羽飞's avatar
羽飞 已提交
37
RC TrxKit::init_global(const char *name)
38
{
羽飞's avatar
羽飞 已提交
39 40 41 42 43
  ASSERT(global_trxkit == nullptr, "init global trx kit twice");
  TrxKit *trx_kit = create(name);
  if (nullptr == trx_kit) {
    LOG_ERROR("failed to create trx kit by name. name=%s", name);
    return RC::INTERNAL;
羽飞's avatar
羽飞 已提交
44 45
  }

羽飞's avatar
羽飞 已提交
46 47 48
  RC rc = trx_kit->init();
  if (rc == RC::SUCCESS) {
    global_trxkit = trx_kit;
羽飞's avatar
羽飞 已提交
49 50 51 52
  }
  return rc;
}

羽飞's avatar
羽飞 已提交
53
TrxKit *TrxKit::instance()
54
{
羽飞's avatar
羽飞 已提交
55 56
  return global_trxkit;
}