Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3378027
D3179.id9712.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D3179.id9712.diff
View Options
diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h
--- a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h
+++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h
@@ -34,7 +34,8 @@
void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
std::string getTableName() const override;
- std::string getPrimaryKey() const override;
+ PrimaryKey getPrimaryKey() const override;
+ PrimaryKeyValue getPrimaryKeyValue() const override;
std::string getBlobHash() const;
S3Path getS3Path() const;
diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp
--- a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp
+++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp
@@ -49,8 +49,12 @@
return BlobItem::tableName;
}
-std::string BlobItem::getPrimaryKey() const {
- return BlobItem::FIELD_BLOB_HASH;
+PrimaryKey BlobItem::getPrimaryKey() const {
+ return PrimaryKey(BlobItem::FIELD_BLOB_HASH);
+}
+
+PrimaryKeyValue BlobItem::getPrimaryKeyValue() const {
+ return PrimaryKeyValue(this->blobHash);
}
std::string BlobItem::getBlobHash() const {
diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h
--- a/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h
+++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h
@@ -3,6 +3,7 @@
#include <aws/core/Aws.h>
#include <aws/dynamodb/DynamoDBClient.h>
+#include <memory>
#include <string>
namespace comm {
@@ -12,12 +13,34 @@
typedef Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue>
AttributeValues;
+struct PrimaryKeyBase {
+ PrimaryKeyBase(const std::string partitionKey)
+ : partitionKey(partitionKey), sortKey(nullptr) {
+ }
+ PrimaryKeyBase(const std::string partitionKey, const std::string sortKey)
+ : partitionKey(partitionKey),
+ sortKey(std::make_unique<std::string>(sortKey)) {
+ }
+
+ const std::string partitionKey;
+ std::unique_ptr<std::string> sortKey;
+};
+
+struct PrimaryKey : PrimaryKeyBase {
+ using PrimaryKeyBase::PrimaryKeyBase;
+};
+
+struct PrimaryKeyValue : PrimaryKeyBase {
+ using PrimaryKeyBase::PrimaryKeyBase;
+};
+
class Item {
virtual void validate() const = 0;
public:
virtual std::string getTableName() const = 0;
- virtual std::string getPrimaryKey() const = 0;
+ virtual PrimaryKey getPrimaryKey() const = 0;
+ virtual PrimaryKeyValue getPrimaryKeyValue() const = 0;
virtual void assignItemFromDatabase(const AttributeValues &itemFromDB) = 0;
};
diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h
--- a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h
+++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h
@@ -28,7 +28,9 @@
void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
std::string getTableName() const override;
- std::string getPrimaryKey() const override;
+ PrimaryKey getPrimaryKey() const override;
+ PrimaryKeyValue getPrimaryKeyValue() const override;
+
std::string getHolder() const;
std::string getBlobHash() const;
};
diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp
--- a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp
+++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp
@@ -42,8 +42,12 @@
return ReverseIndexItem::tableName;
}
-std::string ReverseIndexItem::getPrimaryKey() const {
- return ReverseIndexItem::FIELD_HOLDER;
+PrimaryKey ReverseIndexItem::getPrimaryKey() const {
+ return PrimaryKey(ReverseIndexItem::FIELD_HOLDER);
+}
+
+PrimaryKeyValue ReverseIndexItem::getPrimaryKeyValue() const {
+ return PrimaryKeyValue(this->holder);
}
std::string ReverseIndexItem::getHolder() const {
diff --git a/services/blob/docker-server/contents/server/src/DatabaseManager.h b/services/blob/docker-server/contents/server/src/DatabaseManager.h
--- a/services/blob/docker-server/contents/server/src/DatabaseManager.h
+++ b/services/blob/docker-server/contents/server/src/DatabaseManager.h
@@ -35,7 +35,7 @@
template <typename T>
std::shared_ptr<T>
innerFindItem(Aws::DynamoDB::Model::GetItemRequest &request);
- void innerRemoveItem(const Item &item, const std::string &key);
+ void innerRemoveItem(const Item &item);
public:
static DatabaseManager &getInstance();
diff --git a/services/blob/docker-server/contents/server/src/DatabaseManager.cpp b/services/blob/docker-server/contents/server/src/DatabaseManager.cpp
--- a/services/blob/docker-server/contents/server/src/DatabaseManager.cpp
+++ b/services/blob/docker-server/contents/server/src/DatabaseManager.cpp
@@ -27,13 +27,19 @@
}
}
-void DatabaseManager::innerRemoveItem(
- const Item &item,
- const std::string &key) {
+void DatabaseManager::innerRemoveItem(const Item &item) {
Aws::DynamoDB::Model::DeleteItemRequest request;
request.SetTableName(item.getTableName());
+ PrimaryKey pk = item.getPrimaryKey();
+ PrimaryKeyValue primaryKeyValue = item.getPrimaryKeyValue();
request.AddKey(
- item.getPrimaryKey(), Aws::DynamoDB::Model::AttributeValue(key));
+ pk.partitionKey,
+ Aws::DynamoDB::Model::AttributeValue(primaryKeyValue.partitionKey));
+ if (pk.sortKey != nullptr && primaryKeyValue.sortKey != nullptr) {
+ request.AddKey(
+ *pk.sortKey,
+ Aws::DynamoDB::Model::AttributeValue(*primaryKeyValue.sortKey));
+ }
const Aws::DynamoDB::Model::DeleteItemOutcome &outcome =
getDynamoDBClient()->DeleteItem(request);
@@ -69,7 +75,11 @@
}
void DatabaseManager::removeBlobItem(const std::string &blobHash) {
- this->innerRemoveItem(*(createItemByType<BlobItem>()), blobHash);
+ std::shared_ptr<BlobItem> item = this->findBlobItem(blobHash);
+ if (item == nullptr) {
+ return;
+ }
+ this->innerRemoveItem(*item);
}
void DatabaseManager::putReverseIndexItem(const ReverseIndexItem &item) {
@@ -133,7 +143,7 @@
if (item == nullptr) {
return false;
}
- this->innerRemoveItem(*item, item->getHolder());
+ this->innerRemoveItem(*item);
return true;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 8:39 AM (18 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593437
Default Alt Text
D3179.id9712.diff (6 KB)
Attached To
Mode
D3179: [services] Blob - Fix logic for primary key
Attached
Detach File
Event Timeline
Log In to Comment