Do I need to consider Etag in Azure Table Storage when performing Update element?
up vote
0
down vote
favorite
I don't know if I need to consider ETag for preventing multiple threads operating a single entity at the same time.
Below is my current implementation:
public void UpdateElement(T element)
{
Exceptions.ThrowIfNull(element, "record");
var partitionKey = element.PartitionKey;
var rowKey = element.RowKey;
var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey));
if (result?.Result != null)
{
Table.Execute(TableOperation.Replace(element));
}
}
So what I'm trying to achieve here is, thread A & thread B are operating the same entity at the same time, and thread A updated this entity first. When thread B is trying to update it, we should give thread B an error saying "you can not perform the update action".
|
show 1 more comment
up vote
0
down vote
favorite
I don't know if I need to consider ETag for preventing multiple threads operating a single entity at the same time.
Below is my current implementation:
public void UpdateElement(T element)
{
Exceptions.ThrowIfNull(element, "record");
var partitionKey = element.PartitionKey;
var rowKey = element.RowKey;
var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey));
if (result?.Result != null)
{
Table.Execute(TableOperation.Replace(element));
}
}
So what I'm trying to achieve here is, thread A & thread B are operating the same entity at the same time, and thread A updated this entity first. When thread B is trying to update it, we should give thread B an error saying "you can not perform the update action".
Where does variableelementcome from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, ifelementis constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation sinceelementdoesn't contains any ETag.
– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you whereelementcomes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it toelementdoesn't make sense.
– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I don't know if I need to consider ETag for preventing multiple threads operating a single entity at the same time.
Below is my current implementation:
public void UpdateElement(T element)
{
Exceptions.ThrowIfNull(element, "record");
var partitionKey = element.PartitionKey;
var rowKey = element.RowKey;
var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey));
if (result?.Result != null)
{
Table.Execute(TableOperation.Replace(element));
}
}
So what I'm trying to achieve here is, thread A & thread B are operating the same entity at the same time, and thread A updated this entity first. When thread B is trying to update it, we should give thread B an error saying "you can not perform the update action".
I don't know if I need to consider ETag for preventing multiple threads operating a single entity at the same time.
Below is my current implementation:
public void UpdateElement(T element)
{
Exceptions.ThrowIfNull(element, "record");
var partitionKey = element.PartitionKey;
var rowKey = element.RowKey;
var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey));
if (result?.Result != null)
{
Table.Execute(TableOperation.Replace(element));
}
}
So what I'm trying to achieve here is, thread A & thread B are operating the same entity at the same time, and thread A updated this entity first. When thread B is trying to update it, we should give thread B an error saying "you can not perform the update action".
edited Nov 20 at 2:00
Zhaoxing Lu - Microsoft
3,378621
3,378621
asked Nov 19 at 22:38
Sherry629629
154
154
Where does variableelementcome from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, ifelementis constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation sinceelementdoesn't contains any ETag.
– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you whereelementcomes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it toelementdoesn't make sense.
– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10
|
show 1 more comment
Where does variableelementcome from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, ifelementis constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation sinceelementdoesn't contains any ETag.
– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you whereelementcomes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it toelementdoesn't make sense.
– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10
Where does variable
element come from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, if element is constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation since element doesn't contains any ETag.– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Where does variable
element come from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, if element is constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation since element doesn't contains any ETag.– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you where
element comes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it to element doesn't make sense.– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you where
element comes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it to element doesn't make sense.– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
In a word, ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations.
- If the variable
elementis fetched from server query, it already contains theETagcoming from server side, you don't need to retrieve it again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))
- If the variable
elementis constructed from client side, retrievingETagfrom server side and set it toelementdoesn't make much sense.
Please check "Managing Concurrency in the Table Service" part in https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ for more details.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383669%2fdo-i-need-to-consider-etag-in-azure-table-storage-when-performing-update-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
In a word, ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations.
- If the variable
elementis fetched from server query, it already contains theETagcoming from server side, you don't need to retrieve it again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))
- If the variable
elementis constructed from client side, retrievingETagfrom server side and set it toelementdoesn't make much sense.
Please check "Managing Concurrency in the Table Service" part in https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ for more details.
add a comment |
up vote
0
down vote
accepted
In a word, ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations.
- If the variable
elementis fetched from server query, it already contains theETagcoming from server side, you don't need to retrieve it again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))
- If the variable
elementis constructed from client side, retrievingETagfrom server side and set it toelementdoesn't make much sense.
Please check "Managing Concurrency in the Table Service" part in https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ for more details.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
In a word, ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations.
- If the variable
elementis fetched from server query, it already contains theETagcoming from server side, you don't need to retrieve it again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))
- If the variable
elementis constructed from client side, retrievingETagfrom server side and set it toelementdoesn't make much sense.
Please check "Managing Concurrency in the Table Service" part in https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ for more details.
In a word, ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations.
- If the variable
elementis fetched from server query, it already contains theETagcoming from server side, you don't need to retrieve it again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))
- If the variable
elementis constructed from client side, retrievingETagfrom server side and set it toelementdoesn't make much sense.
Please check "Managing Concurrency in the Table Service" part in https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ for more details.
answered Nov 28 at 2:09
Zhaoxing Lu - Microsoft
3,378621
3,378621
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383669%2fdo-i-need-to-consider-etag-in-azure-table-storage-when-performing-update-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Where does variable
elementcome from? If it's from server query, then it already contains the ETag, you don't need to retrieve the entity again likevar result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey)). Besides, ifelementis constructed from client side and doesn't come from server query, your code above doesn't really check ETag as your expectation sinceelementdoesn't contains any ETag.– Zhaoxing Lu - Microsoft
Nov 20 at 2:05
Thanks for you answer! But I want to know which value we should give for setting a Etag. for example, I have two threads, thread A & thread B, they both want to update an existing element ELEMENT. in this scenario, how should we set the Etag for A&B's operation? Thanks!
– Sherry629629
Nov 26 at 23:50
ETag is not designed to be set manually. Actually, it's designed for Read-Edit-Write scenario and preventing Dirty Write due to concurrent operations. That's why I asked you where
elementcomes from: if it's fetched from server query, it already contains the ETag; if it's constructed from client side, retrieving ETag from server side and set it toelementdoesn't make sense.– Zhaoxing Lu - Microsoft
Nov 27 at 1:21
I'd suggest you to read "Managing Concurrency in the Table Service" part in azure.microsoft.com/en-us/blog/… .
– Zhaoxing Lu - Microsoft
Nov 27 at 1:23
I've put the above explanation in answer, could you please accept it?
– Zhaoxing Lu - Microsoft
Nov 28 at 2:10