Skip to content
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

Closed
wants to merge 8 commits into from
Closed

fix issue #463 #476

wants to merge 8 commits into from

Conversation

winkyao
Copy link
Contributor

@winkyao winkyao commented Oct 28, 2015

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)
Copy link
Member

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.

Copy link
Contributor Author

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..

Copy link
Member

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.

Copy link
Contributor Author

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. :-)

Copy link
Member

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. :-)

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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.

@siddontang
Copy link
Member

I think we should check constraints before handing row data. :-)

table/tables/tables.go: before create index add checkCreateUnqIdxAvail and checkUpdateUnqIdxAvail

tidb_test.go: add issue #463 test case

for fix the issue #463: #463
@winkyao
Copy link
Contributor Author

winkyao commented Oct 29, 2015

@siddontang @shenli

@ngaut
Copy link
Member

ngaut commented Oct 29, 2015

Thanks @winkyao
Have you tried some tests like:

  1. Update the same value multiple times.
  2. Delete and insert again.
    All of those operations inside a transaction.

@winkyao
Copy link
Contributor Author

winkyao commented Oct 29, 2015

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) {
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment problem.

@winkyao
Copy link
Contributor Author

winkyao commented Oct 29, 2015

@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 {
Copy link
Member

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.

Copy link
Contributor Author

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?

@siddontang
Copy link
Member

@winkyao The newest master has already supported index Exist function, you can use it directly.

@winkyao
Copy link
Contributor Author

winkyao commented Nov 3, 2015

@siddontang I have other works these days, so I can not fix it recently. May you fix it? I am very sorry.

@siddontang
Copy link
Member

Thanks, if we will fix this issue, we will tell you :-)

@disksing
Copy link
Contributor

disksing commented Dec 4, 2015

Hi @winkyao :
We have fixed this issue in another approach. Please refer #670 for more details.
I will close this PR. Thanks for your contribution.

@disksing disksing closed this Dec 4, 2015
YuJuncen pushed a commit to YuJuncen/tidb that referenced this pull request Apr 23, 2021
* 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
YuJuncen pushed a commit to YuJuncen/tidb that referenced this pull request Apr 23, 2021
* 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]>
nolouch pushed a commit to nolouch/tidb that referenced this pull request Jul 13, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants