MetaInfo.h 10.7 KB
Newer Older
W
wangyunlai.wyl 已提交
1 2 3 4 5 6 7 8 9 10
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
oblogmsg 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. */

11
#pragma once
忠阳 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

#include <cstdio>
#include <ctime>
#include <pthread.h>
#include <vector>
#include <string>
#include "UserData.h"

namespace oceanbase {
namespace logmessage {

class StrArray;

enum logmsg_field_types {
  LOGMSG_TYPE_DECIMAL,
  LOGMSG_TYPE_TINY,
  LOGMSG_TYPE_SHORT,
  LOGMSG_TYPE_LONG,
  LOGMSG_TYPE_FLOAT,
  LOGMSG_TYPE_DOUBLE,
  LOGMSG_TYPE_NULL,
  LOGMSG_TYPE_TIMESTAMP,
  LOGMSG_TYPE_LONGLONG,
  LOGMSG_TYPE_INT24,
  LOGMSG_TYPE_DATE,
  LOGMSG_TYPE_TIME,
  LOGMSG_TYPE_DATETIME,
  LOGMSG_TYPE_YEAR,
  LOGMSG_TYPE_NEWDATE,
  LOGMSG_TYPE_VARCHAR,
  LOGMSG_TYPE_BIT,

  LOGMSG_TYPE_NEWDECIMAL = 246,
  LOGMSG_TYPE_ENUM = 247,
  LOGMSG_TYPE_SET = 248,
  LOGMSG_TYPE_TINY_BLOB = 249,
  LOGMSG_TYPE_MEDIUM_BLOB = 250,
  LOGMSG_TYPE_LONG_BLOB = 251,
  LOGMSG_TYPE_BLOB = 252,
  LOGMSG_TYPE_VAR_STRING = 253,
  LOGMSG_TYPE_STRING = 254,
  LOGMSG_TYPE_GEOMETRY = 255,
  LOGMSG_TYPES
};

// column's meta
struct ColMetaInfo;
class IDBMeta;
class IMetaDataCollections;
struct _trie_tree;
class IColMeta : public UserDataInterface {
public:
  IColMeta();
  IColMeta(const void* ptr, size_t size);
  virtual ~IColMeta();

public:
  // override
  virtual const char* getName();
  virtual int getType();
  virtual long getLength();
自凡 已提交
73 74 75
  virtual const char* getOriginType();
  virtual long getPrecision();
  virtual long getScale();
忠阳 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  virtual bool isSigned();
  virtual bool isPK();
  virtual bool isRuleCol();
  virtual bool isUK();
  virtual bool isNotNull();
  virtual int getDecimals();
  virtual const char* getDefault();
  virtual const char* getEncoding();
  virtual int getRequired();
  virtual StrArray* getValuesOfEnumSet();
  virtual bool isGenerated();
  virtual void setFlag(unsigned char flag);
  virtual unsigned char getFlag();

  virtual void setName(const char* name);
  virtual void setType(int type);
  virtual void setLength(long length);
自凡 已提交
93 94 95
  virtual void setOriginType(const char* origin);
  virtual void setPrecision(long precision);
  virtual void setScale(long scale);
忠阳 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109
  virtual void setSigned(bool b);
  virtual void setIsPK(bool b);
  virtual void setIsRuleCol(bool b);
  virtual void setIsUK(bool b);
  virtual void setNotNull(bool b);
  virtual void setDecimals(int decimals);
  virtual void setDefault(const char* def);
  virtual void setDefault(const char* def, size_t length);
  virtual void setEncoding(const char* enc);
  virtual void setRequired(int required);
  virtual void setValuesOfEnumSet(std::vector<std::string>& v);
  virtual void setValuesOfEnumSet(std::vector<const char*>& v);
  virtual void setValuesOfEnumSet(const char** v, size_t size);

自凡 已提交
110 111
  virtual void setGenerated(bool generated = true);
  virtual void setHiddenRowKey(bool hiddenRowKey = true);
忠阳 已提交
112
  virtual bool isHiddenRowKey();
自凡 已提交
113
  virtual void setPartitioned(bool partitioned = true);
114
  virtual bool isPartitioned();
自凡 已提交
115
  virtual void setDependent(bool dependent = true);
116
  virtual bool isDependent();
忠阳 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

public:
  int appendTo(std::string& s);
  size_t getRealSize();
  int parse(const void* ptr, size_t size);
  bool parsedOK();

public:
  virtual void setUserData(void* data);
  virtual void* getUserData();

private:
  ColMetaInfo* m_col;
  void* m_userData;
};

// table's meta
struct TableMetaInfo;
class ITableMeta : public UserDataInterface {
public:
  ITableMeta();
  ITableMeta(const void* ptr, size_t size);
  virtual ~ITableMeta();

public:
  // override
  virtual const char* getName();
  virtual bool hasPK();
  virtual bool hasUK();
  virtual const char* getPKs();
  virtual const char* getUKs();
  virtual const int* getPKs(int& size) const;
  virtual const int* getUKs(int& size) const;
  virtual const char* getEncoding();
  virtual IDBMeta* getDBMeta();

  virtual void setName(const char* name);
  virtual void setHasPK(bool b);
  virtual void setPKIndice(const std::vector<int>& indice);
  virtual void setPKs(const char* pks);
  virtual void setHasUK(bool b);
  virtual void setUKs(const char* uks);
  virtual void setEncoding(const char* enc);
  virtual void setDBMeta(IDBMeta* dbMeta);
  virtual void setPkinfo(const char* info);
  virtual const char* getPkinfo();
  virtual void setUkinfo(const char* info);
  virtual const char* getUkinfo();
  bool hashColumnSetted();
  const int* getHashColumnIdx(int& hashCoumnCount, char**& hashValueList, size_t*& hashValueSizeList);
  void setHashColByPK();
  int setHashCol(std::vector<std::string>& hashColumns);
  void setHashFuncId(int id);
  int getHashFuncId();
  void trySerializeMetaDataAsMsgArea(std::vector<const char*>& extra_infos);
  const std::string& getNameData();
  const std::string& getEncodingData();
  const std::string& getcolTypeData();
  const std::string& getPkData();
  const std::string& getUkData();
  const std::string& getkeyData();
  const std::string& getColumnFlagData();
  const std::string& getNotNullData();
  const std::string& getSignedData();
  const std::string& getDecimalsData();
  const std::string& getDefaultData();
自凡 已提交
183 184 185 186
  const std::string& getColLengthData();
  const std::string& getOriginTypeData();
  const std::string& getColPrecisionData();
  const std::string& getColScaleData();
忠阳 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

public:
  /**
   * get all column name
   */
  std::vector<std::string>& getColNames();

  /**
   * get PK column name
   */
  std::vector<std::string>& getPKColNames();
  std::vector<std::string>& getUKColNames();

  /**
   * get column's meta by name
   */
  virtual IColMeta* getCol(const char* colName);

  virtual int getColIndex(const char* colName);

  /**
   * get Column count
   */
  virtual int getColCount();

  /*
   * get column's meta by column id
   */
  virtual IColMeta* getCol(int index);
  virtual int getColNum(const char* colName);

  /**
   * append a column meta
   */
  virtual int append(const char* colName, IColMeta* colMeta);

  /* For partial */
  virtual bool isDropped();
  virtual void setDropped(bool value);
  virtual const char* getNewName();
  virtual void setNewName(const char* name);

public:
  int appendTo(std::string& s);
  size_t getRealSize();
  int parse(const void* ptr, size_t size);
  bool parsedOK();
  /*
   * parse key index like (2, 0, 1) or (0, 1, 2)
   * return index vector, if format is invalid,
   * return -1, if success, return 0.
   */
  int parseKeyIndex(std::string indexStr, std::vector<int>& indice);
  /*
   * get pk or uk keys from pkinfo or ukinfo like (0, 1, 2......)
   */
  int getKeysFromInfo(std::string info, std::string& keys, StrArray* colNames);

public:
  virtual void setUserData(void* data);
  virtual void* getUserData();
  virtual void** getUserDataPtr();

private:
  TableMetaInfo* m_tbl;
  void* m_userData;
  std::string m_colNameData;
  std::string m_encodingData;
  std::string m_colTypeData;
  std::string m_PkData;
  std::string m_UkData;
  std::string m_keyData;
  std::string m_columnFlagData;
  std::string m_colNotNullData;
  std::string m_colSignedData;
  std::string m_colDecimalsData;
  std::string m_colDefaultData;
自凡 已提交
264 265 266 267
  std::string m_colLengthData;
  std::string m_colOriginTypeData;
  std::string m_colPrecisionData;
  std::string m_colScaleData;
忠阳 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417

  pthread_mutex_t m_mdMutex;
  bool m_DataOk;
  int* m_hashColumnIdx;
  int m_hashColumnSize;
  bool m_hashColumnSetted;
  int m_hashFuncId;
  char** m_hashColumValueList;
  size_t* m_hashColumValueSizeList;
};

// DB's meta
struct DBMetaInfo;
class IDBMeta : public UserDataInterface {
public:
  IDBMeta();
  IDBMeta(const void* ptr, size_t size);
  virtual ~IDBMeta();

public:
  // override
  virtual const char* getName();
  virtual const char* getEncoding();
  virtual IMetaDataCollections* getMetaDataCollections();

  virtual void setName(const char* name);
  virtual void setEncoding(const char* enc);
  virtual void setMetaDataCollections(IMetaDataCollections* mdc);

  virtual int getTblCount();
  /**
   * get table's meta by name
   */
  virtual ITableMeta* get(const char* tblName);
  virtual ITableMeta* get(int index);

  /**
   * add a table's meta
   */
  virtual int put(ITableMeta* tblMeta);

  /* For partial */
  virtual bool isDropped();
  virtual void setDropped(bool value);

public:
  virtual int eraseMapIterator();
  virtual int getFromMapIterator(const char** tblName, ITableMeta** tblMeta);
  virtual int nextMapIterator(bool erase);
  virtual int resetMapIterator();
  virtual int erase(const char* tableName, bool delayDeleteMeta);
  virtual int appendTo(std::string& s);
  virtual size_t getRealSize();
  virtual int parse(const void* ptr, size_t size);
  virtual bool parsedOK();

public:
  virtual void setUserData(void* data);
  virtual void* getUserData();
  virtual void** getUserDataPtr();

private:
  DBMetaInfo* m_db;
  void* m_userData;
};

// all db's meta
struct MetaDataCollectionInfo;
class IMetaDataCollections : public UserDataInterface {
public:
  IMetaDataCollections();
  IMetaDataCollections(
      const void* ptr, size_t size, bool removePtr = false);  // removePtr means if free ptr when destroy object
  virtual ~IMetaDataCollections();

public:
  // override
  virtual unsigned getMetaVerNum();
  virtual IMetaDataCollections* getPrev();
  virtual time_t getTimestamp();

  virtual void setMetaVerNum(unsigned metaVerNum);
  virtual void setPrev(IMetaDataCollections* prev);
  virtual void setTimestamp(time_t timestamp);

  /**
   * get Db count
   */
  virtual int getDbCount();

  /**
   * get Db meta by name
   */
  virtual IDBMeta* get(const char* dbname);

  /**
   * get Db meta by id
   */
  virtual IDBMeta* get(int index);

  /**
   * get table meta by dbname and tablename
   */
  virtual ITableMeta* get(const char* dbName, const char* tblName);

  /**
   * add a db meta
   */
  virtual int put(IDBMeta* dbMeta);

  /**
   * serialize to  string
   */
  virtual int toString(std::string& s);

  /**
   * parse from readonly ptr
   */
  virtual int parse(const void* ptr, size_t size);

  /**
   * if parsed success
   */
  virtual bool parsedOK();

  virtual size_t getRealSize();

  virtual int eraseMapIterator();
  virtual int getFromMapIterator(const char** dbName, IDBMeta** dbMeta);
  virtual int nextMapIterator(bool erase);
  virtual int resetMapIterator();
  virtual int erase()
  {
    return 0;
  }
  virtual int erase(const char* dbName, bool delayDeleteMeta);
  virtual int erase(const char* dbName, const char* tbName, bool delayDeleteMeta);

public:
  virtual void setUserData(void* data);
  virtual void* getUserData();

private:
  MetaDataCollectionInfo* m_coll;
  void* m_userData;
};

}  // namespace logmessage
}  // namespace oceanbase