GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Datastore: Divergence in failure treatments in add/put with multiples entities · Issue #1356 · googleapis/google-cloud-java

Datastore: Divergence in failure treatments in add/put with multiples entities #1356

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore: Divergence in failure treatments in add/put with multiples entities#1356
Copy link
Assignees
mziccard

Description

@unitydynamics
unitydynamics
opened on Oct 31, 2016
Issue body actions

I'm using the following code block to generate a big random blob of characters

Random r = new Random();

int msgSize = 5200;  // in KB
msgSize = msgSize/2; // Java chars are 2 bytes
msgSize = msgSize * 1024;
StringBuilder sb = new StringBuilder(msgSize);
for (int i=0; i<msgSize; i++) {
    sb.append((char)(r.nextInt(26) + 'a'));
}

I find that if I put a blob in an entity and store it...

entityBuilder.set("myTextBlob", BlobValue.builder(Blob.copyFrom(sb.toString())).excludeFromIndexes(true).build());

And then build my entity and save it that it works... and all other properties make it into the datastore... but the blob property is silently dropped. Is there a correct way to validate an entity before inserting it? Datastore items are max 1MB in size right?

Activity

Next
  1. sai-pullabhotla commented on Oct 31, 2016

    @sai-pullabhotla
    sai-pullabhotla
    on Oct 31, 2016
    More actions

    @unitydynamics,

    Max entity size is 1 MB, this is the size of all properties in the entity. Attempting to put an entity that is larger than this size should produce a DatastoreException indicating that the entity is too large.

    Can you post the entire code... unless I'm overlooking something, the code you posted most likely won't compile because there is no method to create a Blob from String, .

    BlobValue.builder(Blob.copyFrom(sb.toString()))

  2. mziccard commented on Oct 31, 2016

    @mziccard
    mziccard
    on Oct 31, 2016
    Contributor
    More actions

    Hi @unitydynamics, are you sure?
    First, your code:

    entityBuilder.set("myTextBlob", BlobValue.builder(Blob.copyFrom(sb.toString())).excludeFromIndexes(true).build());
    

    Does not compile as Blob has no copyFrom method that takes a String.

    I tried the following code:

    Random random = new Random();
    byte[] blobArray = new byte[2_000_000];
    random.nextBytes(blobArray);
    
    Key key = datastore.newKeyFactory().setKind("MyKind").newKey("mykey");
    Entity entity = Entity.newBuilder(key1)
        .set("stringProperty", "value")
        .set("integerProperty", 1)
        .set("blobProperty",
            BlobValue.builder(Blob.copyFrom(blobArray))
                .setExcludeFromIndexes(true)
                .build())
        .build();
    
    // using datastore
    datastore.add(entity);
    // or
    Transaction transaction = datastore.newTransaction();
    transaction.add(entity);
    transaction.commit();
    // or
    datastore.put(entity);
    // or 
    Transaction transaction = datastore.newTransaction();
    transaction.out(entity);
    transaction.commit();

    As you can see I tried to insert the entity in different ways. Regardless of the way I get the following error and the entity is not persisted (none of its properties):

    The value of property "blobProperty" is longer than 1048487 bytes.

    This is in line with the limits reported here:

    Maximum size for an entity = 1,048,572 bytes (1 MiB - 4 bytes)
    Maximum size for an unindexed property = 1,048,487 bytes (1 MiB - 89 bytes)

  3. unitydynamics commented on Oct 31, 2016

    @unitydynamics
    unitydynamics
    on Oct 31, 2016
    Author
    More actions

    So yes I have lots of code cut out (I'm compressing text before I put it into the property). I will try to post a short reproducible example tomorrow. Couple of potentially contributing circumstances.... one is that I'm accessing the datastore from outside AppEngine. I've got my certificate installed so I can push entities to production Datastore from my local machine (or compute engine).

  4. mziccard commented on Oct 31, 2016

    @mziccard
    mziccard
    on Oct 31, 2016
    Contributor
    More actions

    one is that I'm accessing the datastore from outside AppEngine.

    This corresponds to the setup I used to run my above (and working as expected) code. I doubt this is a Datastore-related issue.

  5. unitydynamics
    changed the title [-]Datastore: Large blob properties dropped (silently) from entities when stored[/-] [+]Datastore: Divergence in failure treatments in put with multiples entities[/+] on Oct 31, 2016
  6. unitydynamics commented on Oct 31, 2016

    @unitydynamics
    unitydynamics
    on Oct 31, 2016
    Author
    More actions

    So yes this, as originally posted, was a me issue... sorry to take up your time. But I did run into one interesting issue so I changed the title. Per our last issue... I see that "add" makes a best effort to store all good entities in a multiple-entity add (the ones not already inserted always succeed). Well the behavior is slightly different when the entities are too large... the entire operation fails. I would expect (or hope for) consistent behavior from these methods (i.e.. always best efforts on every individual entity). Maybe a different way to fail other than exceptions? Ideally something that allows you to identify the issues (but I recall that may not be possible).

    Random random = new Random();
    byte[] blobArray = new byte[2_000_000];
    random.nextBytes(blobArray);
    
    Datastore datastore = DatastoreOptions.defaultInstance().service();
    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey("mykey");
    Entity entity1 = Entity.builder(key1)
        .set("stringProperty", "value2")
        .set("integerProperty", 1)
        .set("blobProperty",
            BlobValue.builder(Blob.copyFrom("one two three".getBytes()))
                .excludeFromIndexes(true)
                .build())
        .build();
    
    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey("mykey2");
    Entity entity2 = Entity.builder(key2)
        .set("stringProperty", "value2")
        .set("integerProperty", 1)
        .set("blobProperty",
            BlobValue.builder(Blob.copyFrom(blobArray))
                .excludeFromIndexes(true)
                .build())
        .build();
    
    Key key3 = datastore.newKeyFactory().kind("MyKind").newKey("mykey3");
    Entity entity3 = Entity.builder(key3)
        .set("stringProperty", "value2")
        .set("integerProperty", 1)
        .set("blobProperty",
            BlobValue.builder(Blob.copyFrom("four five six".getBytes()))
                .excludeFromIndexes(true)
                .build())
        .build();
    
    // using datastore
    // both of these fail the entire batch
    datastore.add(entity1, entity2, entity3);
    datastore.put(entity1, entity2, entity3);
    
  7. unitydynamics
    changed the title [-]Datastore: Divergence in failure treatments in put with multiples entities[/-] [+]Datastore: Divergence in failure treatments in add/put with multiples entities[/+] on Oct 31, 2016
  8. sai-pullabhotla commented on Oct 31, 2016

    @sai-pullabhotla
    sai-pullabhotla
    on Oct 31, 2016
    More actions

    @mziccard,

    Regarding the max size of an unindexed property -

    Maximum size for an unindexed property = 1,048,487 bytes (1 MiB - 89 bytes)

    I was testing the limits the other day and I was not able to store (1 MiB - 89). I was getting Entity too large exception. After a few trial and errors, I was able to store (1 Mib-129), but that was also failing sporadically with the Entity too large message. Since you seem to have a test case now, would you mind validating this?

  9. unitydynamics commented on Oct 31, 2016

    @unitydynamics
    unitydynamics
    on Oct 31, 2016
    Author
    More actions

    @sai-pullabhotla the exception makes it sound like a field-level limit but it's an entity-as-a-whole size limit right? Variations in you testing may be due to your other entity attributes?

    Regarding how to handle "too large" in general.... Maybe throw the "too large" exception when build() is called on the entity? I know I'd rather know right away. But I know adding size logic isn't necessarily easy.

  10. sai-pullabhotla commented on Oct 31, 2016

    @sai-pullabhotla
    sai-pullabhotla
    on Oct 31, 2016
    More actions

    No, my test case was with just one field with Datastore-generated Integer key.

  11. mziccard commented on Oct 31, 2016

    @mziccard
    mziccard
    on Oct 31, 2016
    Contributor
    More actions

    @sai-pullabhotla I managed to successfully create an Entity with blob of 1,048,487 bytes:

    Random random = new Random();
    byte[] blobArray = new byte[1_048_487];
    random.nextBytes(blobArray);
    
    Key key = Key.newBuilder("my-project", "a", "b").build();
    Entity entity = Entity.newBuilder(key)
        .set("p", BlobValue.newBuilder(Blob.copyFrom(blobArray)).setExcludeFromIndexes(true).build())
        .build();
    datastore.add(entity);

    Which exception were you getting? That should tell you if you are hitting an entity limit or a blob limit.

  12. mziccard commented on Oct 31, 2016

    @mziccard
    mziccard
    on Oct 31, 2016
    Contributor
    More actions

    @unitydynamics I managed to reproduce what you are seeing. @pcostell could you have a look at this comment?

  13. pcostell commented on Oct 31, 2016

    @pcostell
    pcostell
    on Oct 31, 2016
    Contributor
    More actions

    Datastore cannot make guarantees about the success/failure of multi-entity puts. If you need an all-or-nothing rule, you need to use transactions.

    If a non-transactional commit fails, there is no way to know which, if any, of the entities were successfully written.

  14. mziccard commented on Oct 31, 2016

    @mziccard
    mziccard
    on Oct 31, 2016
    Contributor
    More actions

    @pcostell I think the point here is not achieving an all-or-nothing rule, but rather the non-all-or-nothing behavior feeling inconsistent. Let me try to explain:

    1. If entity1.getKey() already exists add(entity1, entity2) fails, but entity2 is inserted.
    2. If entity1 exceeds the size limit add(entity1, entity2) fails, no entity is inserted.

    From 1. users conclude that on a failure multi-entity add inserts all entities that can be inserted. From 2. users conclude that on a failure multi-entity add does not insert anything. I can see from where this comes, but it can still be confusing.

  15. pcostell commented on Oct 31, 2016

    @pcostell
    pcostell
    on Oct 31, 2016
    Contributor
    More actions

    @mziccard you're right, it's definitely inconsistent in non-transactional cases. Really all we can guarantee is all-or-nothing in a transaction. Outside of a transaction the failures can happen at different points in the stack which results in the undefined behavior. I can file some bugs internally to get the documentation to describe this better, but I'm not sure it will be possible to make the behavior itself more well-defined.

  16. 5 remaining items

  17. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore(main): release 3.15.3-SNAPSHOT (#1356)

    2c07fc6
  18. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    cee5317
  19. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore(main): release 2.18.6-SNAPSHOT (#1356)

    dc06564
  20. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore(main): release 3.15.3-SNAPSHOT (googleapis#1356)

    544b62a
  21. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore(main): release 2.13.2-SNAPSHOT (googleapis#1356)

    503752a
  22. suztomo
    added 2 commits that reference this issue on Mar 30, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    a2d5f40

    chore(main): release 0.127.13 (#1358)

    6abbb15
  23. lqiu96
    added 2 commits that reference this issue on Apr 1, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    e8e24dc

    chore(main): release 0.127.13 (#1358)

    210c536
  24. meltsufin
    added 4 commits that reference this issue on Apr 29, 2026

    deps: update dependency com.google.protobuf:protobuf-java-util to v3.…

    dc1e0ca

    chore(main): release 1.120.23 (#1367)

    f1844eb

    deps: update dependency com.google.protobuf:protobuf-java-util to v3.…

    cfda245

    chore(main): release 1.120.23 (#1367)

    8dd53dd
  25. benjaminp
    added 2 commits that reference this issue on Jul 13, 2026

    test(deps): update dependency org.mockito:mockito-core to v4.7.0 (goo…

    3214f51

    feat: Support Cloud Bigtable Changestream (googleapis#1569)

    99071f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.