コード例 #1
0
 def test_scenario_c_server_side_durability(self):
     # Use a helper wrapper to retry our operation in the face of durability failures
     # remove is idempotent iff the app guarantees that the doc's id won't be reused (e.g. if it's a UUID).  This seems
     # a reasonable restriction.
     for durability_type in Durability:
         self.coll.upsert("id","fred",durability=ServerDurability(Durability.NONE))
         self.retry_idempotent_remove_server_side(
             lambda: self.coll.remove("id", RemoveOptions(durability=ServerDurability(durability_type))))
コード例 #2
0
 async def _mdelete(self, key, durability_level=Durability.NONE):
     try:
         await self.cb.remove(
             key,
             RemoveOptions(durability=ServerDurability(durability_level)))
     except DocumentNotFoundException as nf:
         logging.warn(f"[{self.name}] get key not found!  %s: " % nf.key)
     except TimeoutException:
         logging.warn(
             "cluster timed out trying to handle mdelete - cluster may be unstable"
         )
     except NetworkException as nx:
         logging.error("network error")
         logging.error(nx)
     except Exception as ex:
         logging.error(ex)
コード例 #3
0
    def test_scenario_C_clientSideDurability(self):
        """
        Scenario C:

        1) Remove a document with Durability Requirements, both variants, thinking about error handling
        """

        # Use a helper wrapper to retry our operation in the face of durability failures
        # remove is idempotent iff the app guarantees that the doc's id won't be reused (e.g. if it's a UUID).  This seems
        # a reasonable restriction.
        self.coll.upsert("id","test")
        self.assertEqual(self.coll.get("id").content_as[str],"test")
        try:
            self.retry_idempotent_remove_client_side(lambda replicateTo:
                                                 self.coll.remove("id",
                                                                  RemoveOptions(durability=ClientDurability(replicateTo,
                                                                                                            PersistTo.ONE))),
                                                     ReplicateTo.TWO, ReplicateTo.TWO, datetime.datetime.now() + timedelta(seconds=30))
        except NotSupportedException as f:
            raise SkipTest("Using a ClientDurability should work, but it doesn't: {}".format(str(f)))
コード例 #4
0
 def test_server_durable_remove(self):
     if not self.supports_sync_durability():
         raise SkipTest("ServerDurability not supported")
     durability = ServerDurability(level=Durability.PERSIST_TO_MAJORITY)
     self.cb.remove(self.KEY, RemoveOptions(durability=durability))
     self.assertRaises(DocumentNotFoundException, self.cb.get, self.KEY)
コード例 #5
0
 def test_client_durable_remove(self):
     num_replicas = self.bucket._bucket.configured_replica_count
     durability = ClientDurability(persist_to=PersistTo.ONE,
                                   replicate_to=ReplicateTo(num_replicas))
     self.cb.remove(self.KEY, RemoveOptions(durability=durability))
     self.assertRaises(DocumentNotFoundException, self.cb.get, self.KEY)
コード例 #6
0
result = collection.get("document-key")
print(result.content_as[dict])
# end::get[]

# tag::get_timeout[]
opts = GetOptions(timeout=timedelta(seconds=5))
result = collection.get("document-key", opts)
print(result.content_as[dict])
# end::get_timeout[]

try:
    # tag::remove_durability[]
    # remove document with options
    result = collection.remove(
        "document-key",
        RemoveOptions(cas=12345,
                      durability=ServerDurability(Durability.MAJORITY)))
    # end::remove_durability[]
except CouchbaseException as ex:
    # we expect an exception here as the CAS value is chosen
    # for example purposes
    pass

# tag::touch[]
result = collection.touch("document-key", timedelta(seconds=10))
# end::touch[]

# tag::get_expiry[]
result = collection.get("document-key", GetOptions(with_expiry=True))
print("Expiry of result: {}".format(result.expiryTime))
# end::get_expiry[]
コード例 #7
0
----
          ----


          == Removing

When removing a document, you will have the same concern for durability as with any additive modification to the Bucket:

    Remove (with options)
[source,python]
----
"""
#tag::remove_old_durability[]
result = collection.remove(
    "document-key",
    RemoveOptions(cas=12345,
                  durability=ClientDurability(PersistTo.ONE, ReplicateTo.ONE)))
#end::remove_old_durability[]
"""
----

== Expiration / TTL

By default, Couchbase documents do not expire, but transient or temporary data may be needed for user sessions, caches, or other temporary documents.
Using `Touch()`, you can set expiration values on documents to handle transient data:

    [source,csharp]
    ----
"""
#tag::touch[]
result = collection.touch("document-key", timedelta(seconds=10))
#end::touch[]