-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue #463 #476
fix issue #463 #476
Conversation
Merge pull request from pingcap/tidb
to delete the discard index keys when we enconter error in table.AddRecord.(which fix issue 463: #463)
Merge pull request from pingcap/tidb
break | ||
} | ||
colVals, _ := v.FetchValues(r) | ||
_ = v.X.Delete(txn, colVals, recordID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This maybe not correct. You want to delete dirty data, but this may delete the data in kv.
For example there is a row [2, 2] already in kv store and you insert [2, 1] and meet ErrKeyExists. In this case, you may delete the correct index for row [2, 2].
I think it is better to check constraints before creating index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this, but in here, it is correct, because if the index key is already exist, it will not be delete in the delDirtyIndexKey, so the delDirtyIndexKey will only delete the index key in dirty strore that created incorrectly. Please note:
if i >= createdIdx {
break
}
and in your mention case, it will not delete the index for row [2, 2]..., because the createdIdx is 0.
"I think it is better to check constraints before creating index." imagine if you have more than one unique index..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right. It is ok here.
But when executing update statements, you will meet similar problem. There is also a bug in update statement, we update row data before updating index. So if meet keyexist error when updating index, unionstore is still dirty.
So I think it may be better to provide some mechanism to check index constraints before operating unionstore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um, sorry...I am not familiar with the update statements, I will read it then find anathor better solution. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@winkyao you can supply a CheckContraint function or other, so that before insert and update, we can use this to check whether we can handle this row or not. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some troubles that I check the index are all available to create, then I create the indices, but the check and create is not a atomic operation, so I may fail when I create one of the indices which is created by other people in the interval..
maybe I use delDirtyIndexKey in update statement is a ugly, but a available solution?
@siddontang @shenli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be detected at the commit stage and will cause error. The whole txn will rollback.
I think it is another scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's complicated. For issue #463, we should rollback, since the state is auto_commit=1.
I think we should check constraints before handing row data. :-) |
Thanks @winkyao
|
um...@ngaut some test run two parallel transaction. |
@@ -237,6 +271,27 @@ func (c *kvIndex) Seek(txn Transaction, indexedValues []interface{}) (iter Index | |||
return &indexIter{it: it, idx: c, prefix: c.prefix}, hit, nil | |||
} | |||
|
|||
// check if the index is duplicated, only check the unique index | |||
func (c *kvIndex) CheckUnique(txn Transaction, indexedValues []interface{}, h int64) (duplicate bool, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckDuplicated may be better with above comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment problem.
@siddontang Done! |
// If the index is unique and there already exists an entry with the same key, Create will continue, and failed when commit | ||
// MustCreate must call after the CheckDuplicated, which tell there is no duplicate key, and if someone create the same index between CheckDuplicated | ||
// and MustCreate, finally our transaction commit will fail, so it is ok. | ||
func (c *kvIndex) MustCreate(txn Transaction, indexedValues []interface{}, h int64) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to fail if we call it "Must". "Create" is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the Index.Create is already exist..so what name you think is better?
@winkyao The newest master has already supported index Exist function, you can use it directly. |
@siddontang I have other works these days, so I can not fix it recently. May you fix it? I am very sorry. |
Thanks, if we will fix this issue, we will tell you :-) |
* support s3 seek end * support nil for WalkOption * try parse range info from respose * fix test * fix lint * fix a bug in s3 WalkDir * update * update * fix * loop read s3 reader * fix lint * fix more lint * fmt * use io.ReadFull instead of manual loop * fix * fix * add a comment for the reason to put in struct * add a comment
* retry write&ingest range * more robust retry ranges * fix * simplify code and add a log Co-authored-by: lance6716 <[email protected]> Co-authored-by: kennytm <[email protected]>
…shutting down (pingcap#476) * test for small ttl of etcd key Signed-off-by: zeminzhou <[email protected]> * domain, tidb-server: stop launching new auto analyze job when shutting down (pingcap#41346) close pingcap#41318 * clean other change Signed-off-by: zeminzhou <[email protected]> --------- Signed-off-by: zeminzhou <[email protected]> Co-authored-by: Yifan Xu <[email protected]>
#463