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










share|improve this question
























  • 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










  • 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've put the above explanation in answer, could you please accept it?
    – Zhaoxing Lu - Microsoft
    Nov 28 at 2:10















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










share|improve this question
























  • 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










  • 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've put the above explanation in answer, could you please accept it?
    – Zhaoxing Lu - Microsoft
    Nov 28 at 2:10













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










share|improve this question















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







azure-table-storage etag






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 2:00









Zhaoxing Lu - Microsoft

3,378621




3,378621










asked Nov 19 at 22:38









Sherry629629

154




154












  • 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










  • 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'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












  • 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












  • 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












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 element is fetched from server query, it already contains the ETag coming from server side, you don't need to retrieve it again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))

  • If the variable element is constructed from client side, retrieving ETag from server side and set it to element doesn'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.






share|improve this answer





















    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
    });


    }
    });














    draft saved

    draft discarded


















    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 element is fetched from server query, it already contains the ETag coming from server side, you don't need to retrieve it again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))

    • If the variable element is constructed from client side, retrieving ETag from server side and set it to element doesn'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.






    share|improve this answer

























      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 element is fetched from server query, it already contains the ETag coming from server side, you don't need to retrieve it again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))

      • If the variable element is constructed from client side, retrieving ETag from server side and set it to element doesn'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.






      share|improve this answer























        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 element is fetched from server query, it already contains the ETag coming from server side, you don't need to retrieve it again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))

        • If the variable element is constructed from client side, retrieving ETag from server side and set it to element doesn'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.






        share|improve this answer












        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 element is fetched from server query, it already contains the ETag coming from server side, you don't need to retrieve it again like var result = Table.Execute(TableOperation.Retrieve<T>(partitionKey, rowKey))

        • If the variable element is constructed from client side, retrieving ETag from server side and set it to element doesn'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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 at 2:09









        Zhaoxing Lu - Microsoft

        3,378621




        3,378621






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga