Transaktionstabellen mit Dataproc Metastore verwenden
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Transaktionen mit ACID-Semantik werden von Apache Hive-Metastores in Dataproc Metastore unterstützt. Weitere Informationen finden Sie unter Hive-Transaktionen.
Diese Transaktionen sind in Hive 3 standardmäßig aktiviert.
Konfigurationen
Sie müssen serverseitige und clientseitige Konfigurationen festlegen, um die Transaktionsunterstützung zu aktivieren.
Serverseitige Konfigurationen
Die folgenden serverseitigen Konfigurationen werden standardmäßig bei der Erstellung des Dienstes durch Dataproc Metastore festgelegt. Sie können diese überschreiben, indem Sie unter Metastore config overrides (Überschreibungen der Metastore-Konfiguration) Überschreibungen für Key (Schlüssel) und Value (Wert) eingeben.
metastore.compactor.initiator.on: Gibt an, ob der Initiator und die Bereinigungsthreads im Dataproc Metastore-Dienst ausgeführt werden sollen.
Setzen Sie den Wert auf true, um den Initiator zu aktivieren.
metastore.compactor.worker.threads: Die Anzahl der Compactor-Worker-Threads, die im Dataproc-Metastore ausgeführt werden sollen.
Legen Sie eine positive Zahl fest, um den Compactor zu aktivieren. Wenn Sie hier eine höhere Zahl festlegen, kann sich das auf die Leistung des Dienstes auswirken, insbesondere wenn Sie die Entwicklerstufe nutzen. Wenn diese Zahl angepasst werden muss, empfehlen wir einen niedrigeren Wert, z. B. 8.
hive.metastore.event.db.notification.api.auth: Gibt an, ob der Dataproc Metastore-Dienst die APIs für Datenbankbenachrichtigungen autorisieren sollte.
Legen Sie false fest. Wenn true festgelegt ist, haben nur die Superuser in den Proxy-Einstellungen die Berechtigung. Weitere Informationen zur Superuser-Proxy-Berechtigung finden Sie unter Sicherheit der Metastore Notification API.
Clientseitige Konfigurationen
Clientseitige Konfigurationen werden im Hive-Client festgelegt, wie unter Transaktionen validieren beschrieben.
hive.support.concurrency: Legen Sie hierfür den Wert true fest, um Transaktionen zum Einfügen, Aktualisieren und Löschen zu unterstützen.
hive.exec.dynamic.partition.mode: Im strikten Modus müssen Sie mindestens eine statische Partition für den Fall angeben, dass alle Partitionen versehentlich überschrieben werden. Im nicht strikten Modus dürfen alle Partitionen dynamisch sein.
Legen Sie hierfür den Wert nonstrict fest, um Transaktionen zum Einfügen, Aktualisieren und Löschen zu unterstützen.
hive.txn.manager: Legen Sie hierfür den Wert org.apache.hadoop.hive.ql.lockmgr.DbTxnManager fest.
Transaktionen prüfen
Sie können Hive-Transaktionen mit einem Dataproc-Cluster validieren, der einen Dataproc Metastore-Dienst unter Hive 3 verwendet.
Sie müssen den Dataproc-Cluster im selben Projekt wie den Dataproc Metastore-Dienst und mit Hive 3 erstellen. Die Dataproc-Images 2.0, 2.0-ubuntu18 und 2.0-debian10 unterstützen Hive 3 und Transaktionen. Mit dem Flag --image-version können Sie das 2.0-Bild festlegen. Beispiel:
In der folgenden Anleitung wird gezeigt, wie Sie Transaktionen in Ihrem Dataproc Metastore-Dienst validieren, der von einem Dataproc-Cluster verwendet wird.
Stellen Sie eine SSH-Verbindung zum Dataproc-Cluster her. Sie können dazu einen Browser oder die Befehlszeile verwenden.
Führen Sie den Befehl hive aus, um den Hive-Client zu öffnen:
$>hive
Richten Sie die clientseitigen Konfigurationen ein, um die Hive-ACID-Unterstützung für Transaktionen in der Hive-Clientsitzung zu aktivieren.
SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
SET hive.support.concurrency=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
Erstellen Sie eine Transaktionstabelle zum Einfügen und Aktualisieren von Daten. Folgendes ist ein Beispiel.
Transaktionstabelle erstellen:
create table student (id int, name string, age int)
STORED AS ORC TBLPROPERTIES ('transactional' = 'true');
Prüfen Sie, ob die Tabelle transaktional ist.
describe formatted <tableName>;
Eine Liste der Tabelleneigenschaften wird ausgegeben. Eine transaktionale Tabelle hat transactional=true in ihren Tabellenparametern.
Beobachten Sie den Deltaordner, der im Verzeichnis student des Warehouse-Verzeichnisses des Dienstes erstellt wurde. Wenn Sie mehrere Insert- oder Update-Anweisungen ausführen, werden mehrere Deltaordner erstellt.
Sehen Sie sich an, welche Komprimierungen gerade ausgeführt werden und welchen Status sie haben. Hive-Metastore führt alle fünf Minuten einen Thread mit dem Namen Initiator aus, um nach Tabellen zu suchen, die verdichtet werden müssen, und fordert die Verdichtung für diese Tabellen an.
show compactions;
So legen Sie eine manuelle Komprimierung fest: entweder klein oder groß.
ALTER TABLE student COMPACT 'minor';
ALTER TABLE student COMPACT 'major';
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-02 (UTC)."],[[["\u003cp\u003eApache Hive metastores in Dataproc Metastore support transactions with ACID semantics, enabled by default on Hive 3.\u003c/p\u003e\n"],["\u003cp\u003eServer-side configurations for transaction support, such as \u003ccode\u003emetastore.compactor.initiator.on\u003c/code\u003e and \u003ccode\u003emetastore.compactor.worker.threads\u003c/code\u003e, are set by default during Dataproc Metastore service creation.\u003c/p\u003e\n"],["\u003cp\u003eClient-side configurations like \u003ccode\u003ehive.support.concurrency\u003c/code\u003e, \u003ccode\u003ehive.exec.dynamic.partition.mode\u003c/code\u003e, and \u003ccode\u003ehive.txn.manager\u003c/code\u003e must be set in the Hive client to enable transactions.\u003c/p\u003e\n"],["\u003cp\u003eYou can validate Hive transactions using a Dataproc cluster with Hive 3, ensuring the cluster and Dataproc Metastore service are in the same project.\u003c/p\u003e\n"],["\u003cp\u003eThe Enterprise tier supports managed asynchronous compactions, which is accessible through the Canary release channel.\u003c/p\u003e\n"]]],[],null,["# Use transactional tables with Dataproc Metastore\n\nTransactions with ACID semantics is supported by [Apache Hive](https://hive.apache.org/)\nmetastores in Dataproc Metastore. For more information, see [Hive Transactions](https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions#HiveTransactions-ACIDandTransactionsinHive).\nThese transactions are enabled by default on Hive 3.\n| **Note:** The `Enterprise` tier supports fully managed asynchronous compaction workflows, which is accessible through the [`Canary` release channel](/dataproc-metastore/docs/release-channel).\n\nConfigurations\n--------------\n\nYou must set server and client side configurations in order to enable\ntransaction support.\n| **Note:** These configurations are set by default for Dataproc Metastore services created with Hive version 3.1.2.\n\n### Server side configurations\n\nThe following server side configurations are set by default during the creation\nof the service by Dataproc Metastore. You can choose to override\nthese by entering **Key** and **Value** overrides under **Metastore config\noverrides**.\n| **Caution:** Changing these configurations while creating a Hive 3 Dataproc Metastore service may result in unexpected errors or cause the service to not work correctly.\n\n- **`metastore.compactor.initiator.on`** --- Whether to run the initiator\n and cleaner threads on the Dataproc Metastore service.\n\n Set to `true` to enable the initiator.\n- **`metastore.compactor.worker.threads`** --- The number of compactor\n worker threads to run on the Dataproc Metastore.\n\n Set to a positive number to enable the compactor. Setting this to a higher\n number may affect the performance of the service, especially if you're on\n Developer tier. If this number needs to be tweaked, we recommend using a lower\n value, such as 8.\n- **`hive.metastore.event.db.notification.api.auth`** --- Whether the\n Dataproc Metastore service should authorize against database\n notification related APIs.\n\n Set to `false`. If set to `true`, then only the superusers in proxy\n settings have permission. See [Metastore notification API security](https://cwiki.apache.org/confluence/display/Hive/HiveReplicationv2Development#HiveReplicationv2Development-MetastorenotificationAPIsecurity)\n for more information on superuser proxy privilege.\n\n### Client side configurations\n\nClient side configurations are set in the Hive client as described in\n[Validate transactions](#validate-transactions).\n\n- **`hive.support.concurrency`** --- Set to `true` to support insert,\n update, and delete transactions.\n\n- **`hive.exec.dynamic.partition.mode`** --- In strict mode, you must\n specify at least one static partition in case all partitions are accidentally\n overwritten. In nonstrict mode, all partitions are allowed to be dynamic.\n\n Set to `nonstrict` to support insert, update, and delete transactions.\n- **`hive.txn.manager`** --- Set to `org.apache.hadoop.hive.ql.lockmgr.DbTxnManager`.\n\nValidate transactions\n---------------------\n\nYou can validate Hive transactions using a Dataproc cluster that uses a\nDataproc Metastore service on Hive 3.\n\nYou must create the Dataproc cluster in the same project as the\nDataproc Metastore service and with Hive 3. The Dataproc\n2.0 images, 2.0-ubuntu18 and 2.0-debian10, support Hive 3 and transactions. You\ncan use the flag `--image-version` to set the 2.0 image. For example: \n\n gcloud dataproc clusters create \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDATAPROC_CLUSTER_ID\u003c/span\u003e\u003c/var\u003e \\\n --dataproc-metastore=projects/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eLOCATION\u003c/span\u003e\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSERVICE\u003c/span\u003e\u003c/var\u003e \\\n --region=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION\u003c/span\u003e\u003c/var\u003e \\\n --image-version 2.0-debian10\n\nThe following instructions demonstrate how to validate transactions in your\nDataproc Metastore service that is used by a Dataproc\ncluster.\n\n1. SSH into the Dataproc cluster. You can do this from either a\n browser or from the command line.\n\n2. Run the command `hive` to open the Hive client:\n\n $\u003e hive\n\n3. Set up the client side configurations to enable Hive ACID support for\n transactions in the hive client session:\n\n SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;\n SET hive.support.concurrency=true;\n SET hive.exec.dynamic.partition.mode=nonstrict;\n\n4. Create a transactional table to insert and update into. The following is an\n example.\n\n 1. Create a transaction table:\n\n create table student (id int, name string, age int)\n STORED AS ORC TBLPROPERTIES ('transactional' = 'true');\n\n 2. Check if the table is transactional:\n\n describe formatted \u003ctableName\u003e;\n\n A list of the table properties are printed. A transactional table has\n `transactional=true` in its table parameters.\n 3. Insert data into the table:\n\n INSERT INTO student VALUES\n (1, 'Alice', 10),\n (2, 'Bob', 10),\n (3, 'Charlie', 10);\n\n 1. Observe the delta folder created under the `student` directory in the warehouse directory of the service. Multiple delta folders are created if you run multiple insert or update statements.\n 4. View which compactions are running and their statuses. Hive metastore runs\n a thread called initiator every five minutes to check for tables which are\n due for compaction and requests compaction for those tables.\n\n show compactions;\n\n 1. To start a manual compaction (either minor or major):\n\n ALTER TABLE student COMPACT 'minor';\n ALTER TABLE student COMPACT 'major';\n\nWhat's next\n-----------\n\n- [Create a service](/dataproc-metastore/docs/create-service)\n- [Update and delete a service](/dataproc-metastore/docs/manage-service)\n- [Import metadata into a service](/dataproc-metastore/docs/import-metadata)"]]