Skip to content
Snippets Groups Projects
Unverified Commit d0b7143e authored by aptend's avatar aptend Committed by GitHub
Browse files

fix: add createAt column (#4623)

Add createAt column for mo_database and mo_tables

Approved by: @daviszhen, @XuPeng-SH
parent 6539d9e6
No related branches found
No related tags found
No related merge requests found
......@@ -306,14 +306,14 @@ const (
tableNamePos = 1
tableCommentPos = 6
attrNamePos = 16
attrTypPos = 17
charWidthPos = 19
nullablePos = 20
primaryKeyPos = 24
attrCommentPos = 27
showCreateTableAttrCount = 29
attrNamePos = 17
attrTypPos = 18
charWidthPos = 20
nullablePos = 21
primaryKeyPos = 25
attrCommentPos = 28
showCreateTableAttrCount = 30
)
/*
......
......@@ -29,6 +29,7 @@ import (
type accessInfo struct {
TenantID, UserID, RoleID uint32
CreateAt types.Timestamp
}
func (ai *accessInfo) WriteTo(w io.Writer) (n int64, err error) {
......@@ -37,7 +38,10 @@ func (ai *accessInfo) WriteTo(w io.Writer) (n int64, err error) {
return
}
}
return 12, nil
if err = binary.Write(w, binary.BigEndian, int64(ai.CreateAt)); err != nil {
return
}
return 20, nil
}
func (ai *accessInfo) ReadFrom(r io.Reader) (n int64, err error) {
......@@ -46,7 +50,12 @@ func (ai *accessInfo) ReadFrom(r io.Reader) (n int64, err error) {
return
}
}
return 12, nil
at := int64(0)
if err = binary.Read(r, binary.BigEndian, &at); err != nil {
return
}
ai.CreateAt = types.Timestamp(at)
return 20, nil
}
type DBEntry struct {
......@@ -87,6 +96,7 @@ func NewDBEntry(catalog *Catalog, name string, txnCtx txnif.AsyncTxn) *DBEntry {
e.acInfo.TenantID = txnCtx.GetTenantID()
e.acInfo.UserID, e.acInfo.RoleID = txnCtx.GetUserAndRoleID()
}
e.acInfo.CreateAt = types.CurrentTimestamp()
return e
}
......@@ -134,10 +144,11 @@ func (e *DBEntry) Compare(o common.NodePayload) int {
return e.DoCompre(oe)
}
func (e *DBEntry) GetTenantID() uint32 { return e.acInfo.TenantID }
func (e *DBEntry) GetUserID() uint32 { return e.acInfo.UserID }
func (e *DBEntry) GetRoleID() uint32 { return e.acInfo.RoleID }
func (e *DBEntry) GetName() string { return e.name }
func (e *DBEntry) GetTenantID() uint32 { return e.acInfo.TenantID }
func (e *DBEntry) GetUserID() uint32 { return e.acInfo.UserID }
func (e *DBEntry) GetRoleID() uint32 { return e.acInfo.RoleID }
func (e *DBEntry) GetCreateAt() types.Timestamp { return e.acInfo.CreateAt }
func (e *DBEntry) GetName() string { return e.name }
func (e *DBEntry) GetFullName() string {
if len(e.fullName) == 0 {
e.fullName = genDBFullName(e.acInfo.TenantID, e.name)
......
......@@ -75,6 +75,7 @@ const (
SystemDBAttr_CreateSQL = "dat_createsql"
SystemDBAttr_Owner = "owner"
SystemDBAttr_Creator = "creator"
SystemDBAttr_CreateAt = "created_time"
SystemDBAttr_AccID = "account_id"
SystemRelAttr_ID = "rel_id"
......@@ -87,6 +88,7 @@ const (
SystemRelAttr_CreateSQL = "rel_createsql"
SystemRelAttr_Owner = "owner"
SystemRelAttr_Creator = "creator"
SystemRelAttr_CreateAt = "created_time"
SystemRelAttr_AccID = "account_id"
SystemColAttr_AccID = "account_id"
......@@ -141,6 +143,10 @@ func init() {
Oid: types.T_uint64,
Size: 8,
}
ttimestamp := types.Type{
Oid: types.T_timestamp,
Size: 8,
}
/*
......@@ -182,6 +188,9 @@ func init() {
if err = SystemDBSchema.AppendCol(SystemDBAttr_Creator, tu32); err != nil {
panic(err)
}
if err = SystemDBSchema.AppendCol(SystemDBAttr_CreateAt, ttimestamp); err != nil {
panic(err)
}
if err = SystemDBSchema.AppendCol(SystemDBAttr_AccID, tu32); err != nil {
panic(err)
}
......@@ -257,6 +266,9 @@ func init() {
if err = SystemTableSchema.AppendCol(SystemRelAttr_Creator, tu32); err != nil {
panic(err)
}
if err = SystemTableSchema.AppendCol(SystemRelAttr_CreateAt, ttimestamp); err != nil {
panic(err)
}
if err = SystemTableSchema.AppendCol(SystemRelAttr_AccID, tu32); err != nil {
panic(err)
}
......
......@@ -46,8 +46,8 @@ func NewTableEntry(db *DBEntry, schema *Schema, txnCtx txnif.AsyncTxn, dataFacto
// Only in unit test, txnCtx can be nil
schema.AcInfo.TenantID = txnCtx.GetTenantID()
schema.AcInfo.UserID, schema.AcInfo.RoleID = txnCtx.GetUserAndRoleID()
}
schema.AcInfo.CreateAt = types.CurrentTimestamp()
e := &TableEntry{
BaseEntry: &BaseEntry{
CommitInfo: CommitInfo{
......
......@@ -2884,8 +2884,8 @@ func TestMultiTenantMoCatalogOps(t *testing.T) {
// [mo_database, mo_tables, mo_columns, 'mo_users_t2' 'test-table-a-timestamp']
checkAllColRowsByScan(t, sysTblTbl, 5, true)
sysColTbl, _ := sysDB.GetRelationByName(catalog.SystemTable_Columns_Name)
// [mo_database(7), mo_tables(11), mo_columns(18), 'mo_users_t2'(1+1), 'test-table-a-timestamp'(2+1)]
checkAllColRowsByScan(t, sysColTbl, 41, true)
// [mo_database(8), mo_tables(12), mo_columns(18), 'mo_users_t2'(1+1), 'test-table-a-timestamp'(2+1)]
checkAllColRowsByScan(t, sysColTbl, 43, true)
}
{
// account 1
......@@ -2905,8 +2905,8 @@ func TestMultiTenantMoCatalogOps(t *testing.T) {
// [mo_database, mo_tables, mo_columns, 'mo_users_t1' 'test-table-a-timestamp']
checkAllColRowsByScan(t, sysTblTbl, 5, true)
sysColTbl, _ := sysDB.GetRelationByName(catalog.SystemTable_Columns_Name)
// [mo_database(7), mo_tables(11), mo_columns(18), 'mo_users_t1'(1+1), 'test-table-a-timestamp'(3+1)]
checkAllColRowsByScan(t, sysColTbl, 42, true)
// [mo_database(8), mo_tables(12), mo_columns(18), 'mo_users_t1'(1+1), 'test-table-a-timestamp'(3+1)]
checkAllColRowsByScan(t, sysColTbl, 44, true)
}
{
// sys account
......@@ -2923,8 +2923,8 @@ func TestMultiTenantMoCatalogOps(t *testing.T) {
// [mo_database, mo_tables, mo_columns, 'mo_accounts']
checkAllColRowsByScan(t, sysTblTbl, 4, true)
sysColTbl, _ := sysDB.GetRelationByName(catalog.SystemTable_Columns_Name)
// [mo_database(7), mo_tables(11), mo_columns(18), 'mo_accounts'(1+1)]
checkAllColRowsByScan(t, sysColTbl, 38, true)
// [mo_database(8), mo_tables(12), mo_columns(18), 'mo_accounts'(1+1)]
checkAllColRowsByScan(t, sysColTbl, 40, true)
}
}
......@@ -269,6 +269,8 @@ func (blk *txnSysBlock) getRelTableData(colIdx int) (view *model.ColumnView, err
colData.Append(schema.AcInfo.RoleID)
case catalog.SystemRelAttr_Creator:
colData.Append(schema.AcInfo.UserID)
case catalog.SystemRelAttr_CreateAt:
colData.Append(schema.AcInfo.CreateAt)
case catalog.SystemRelAttr_AccID:
colData.Append(schema.AcInfo.TenantID)
default:
......@@ -304,6 +306,8 @@ func (blk *txnSysBlock) getDBTableData(colIdx int) (view *model.ColumnView, err
colData.Append(db.GetRoleID())
case catalog.SystemDBAttr_Creator:
colData.Append(db.GetUserID())
case catalog.SystemDBAttr_CreateAt:
colData.Append(db.GetCreateAt())
case catalog.SystemDBAttr_AccID:
colData.Append(db.GetTenantID())
default:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment