forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ddl: allocate the element ID correctly for GC delete range (pingcap#68)
- Loading branch information
Showing
5 changed files
with
115 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ddl | ||
|
||
const ( | ||
elemTable byte = 't' | ||
elemPartition byte = 'p' | ||
elemIndex byte = 'i' | ||
) | ||
|
||
type elementObjID struct { | ||
tp byte | ||
id int64 | ||
} | ||
|
||
type elementIDAlloc struct { | ||
objIDs map[elementObjID]int64 | ||
} | ||
|
||
func (e *elementIDAlloc) allocForIndexID(indexID int64) int64 { | ||
return e.alloc(elemIndex, indexID) | ||
} | ||
|
||
func (e *elementIDAlloc) allocForTableID(tableID int64) int64 { | ||
return e.alloc(elemTable, tableID) | ||
} | ||
|
||
func (e *elementIDAlloc) allocForPartitionID(partitionID int64) int64 { | ||
return e.alloc(elemPartition, partitionID) | ||
} | ||
|
||
func (e *elementIDAlloc) alloc(tp byte, schemaObjID int64) int64 { | ||
if e.objIDs == nil { | ||
e.objIDs = make(map[elementObjID]int64) | ||
} | ||
objID := elementObjID{tp: tp, id: schemaObjID} | ||
if elemID, found := e.objIDs[objID]; found { | ||
return elemID | ||
} | ||
newElemID := int64(len(e.objIDs) + 1) | ||
e.objIDs[objID] = newElemID | ||
return newElemID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.