.replace 盘区.replace extents
此命令在特定数据库的上下文中运行。This command runs in the context of a specific database. 它将指定的区从其源表移至目标表,然后从目标表中删除指定的区。It moves the specified extents from their source tables to the destination table, and then drops the specified extents from the destination table. 所有删除和移动操作都在单个事务中完成。All of the drop and move operations are done in a single transaction.
需要源表和目标表的表管理员权限。Requires Table admin permission for the source and destination tables.
备注
在 Kusto 中,数据分片被称为“盘区”,所有命令都将“extent”或“extents”作为同义词使用。Data shards are called extents in Kusto, and all commands use "extent" or "extents" as a synonym. 若要详细了解区,请参阅区(数据分片)概述。For more information on extents, see Extents (data shards) overview.
语法Syntax
.replace
[async
] extents
in
table
DestinationTableName <| {
查询要从表中删除的盘区},{
查询要移动到表中的盘区}
.replace
[async
] extents
in
table
DestinationTableName <| {
query for extents to be dropped from table},{
query for extents to be moved to table}
async
(可选):以异步方式执行该命令。async
(optional): Execute the command asynchronously.- 返回操作 ID (Guid)。An Operation ID (Guid) is returned.
- 可以监视操作的状态。The operation's status can be monitored. 请使用 .show operations 命令。Use the .show operations command.
- 可以检索成功执行的结果。The results of a successful execution can be retrieved. 请使用 .show operation details 命令。Use the .show operation details command.
若要指定应该删除或移动哪些区,请使用以下两个查询之一。To specify which extents should be dropped or moved, use one of two queries.
- 查询要从表中删除的区:此查询的结果指定应从目标表中删除的区 ID。query for extents to be dropped from table: The results of this query specify the extent IDs that should be dropped from the destination table.
- 查询要移动到表的区:此查询的结果指定源表中应移至目标表的区 ID。query for extents to be moved to table: The results of this query specify the extent IDs in the source tables that should be moved to the destination table.
这两个查询都应返回一个包含名为“ExtentId”的列的记录集。Both queries should return a recordset with a column called "ExtentId".
限制Restrictions
- 源表和目标表都必须位于上下文数据库中。Both source and destination tables must be in the context database.
- 对要从表中删除的盘区的查询所指定的所有盘区应属于目标表。All extents specified by the query for extents to be dropped from table are expected to belong to the destination table.
- 源表中的所有列均应以相同的名称和数据类型存在于目标表中。All columns in the source tables are expected to exist in the destination table with the same name and data type.
返回输出(对于同步执行)Return output (for sync execution)
输出参数Output parameter | 类型Type | 说明Description |
---|---|---|
OriginalExtentIdOriginalExtentId | stringstring | 源表中原始区(已移至目标表)或目标表中已被删除的区的唯一标识符。A unique identifier (GUID) for the original extent in the source table that has been moved to the destination table, or the extent in the destination table that has been dropped. |
ResultExtentIdResultExtentId | stringstring | 已从源表移至目标表的结果区的唯一标识符 (GUID)。A unique identifier (GUID) for the result extent that has been moved from the source table to the destination table. 如果已从目标表中删除该区,则为空。Empty, if the extent was dropped from the destination table. 失败时:“失败”。Upon failure: "Failed". |
详细信息Details | stringstring | 包括失败详细信息(如果操作失败)。Includes the failure details if the operation fails. |
备注
如果目标表中不存在要从表中删除的盘区的查询所返回的盘区,则该命令将失败。The command will fail if extents returned by the extents to be dropped from table query don't exist in the destination table. 如果在执行 replace 命令之前合并了盘区,则可能会发生这种情况。This may happen if the extents were merged before the replace command was executed. 为确保命令在缺失盘区时失败,请检查查询是否返回所需的盘区 ID。To make sure the command fails on missing extents, check that the query returns the expected ExtentIds. 如果表 MyOtherTable 中不存在要删除的区,下面的示例 #1 将会失败。Example #1 below will fail if the extent to drop doesn't exist in table MyOtherTable. 但是,即使要删除的区不存在,示例 #2 也会成功,因为用于执行删除操作的查询未返回任何区 ID。Example #2, however, will succeed even though the extent to drop doesn't exist, since the query to drop didn't return any extent IDs.
示例Examples
移动两个表中所有的区Move all extents from two tables
从两个特定表(MyTable1
、MyTable2
)中将所有区移至表 MyOtherTable
,并删除 MyOtherTable
中标有 drop-by:MyTag
的所有区:Move all extents from two specific tables (MyTable1
, MyTable2
) to table MyOtherTable
, and drop all extents in MyOtherTable
tagged with drop-by:MyTag
:
.replace extents in table MyOtherTable <|
{
.show table MyOtherTable extents where tags has 'drop-by:MyTag'
},
{
.show tables (MyTable1,MyTable2) extents
}
示例输出Sample output
OriginalExtentIdOriginalExtentId | ResultExtentIdResultExtentId | 详细信息Details |
---|---|---|
e133f050-a1e2-4dad-8552-1f5cf47cab69e133f050-a1e2-4dad-8552-1f5cf47cab69 | 0d96ab2d-9dd2-4d2c-a45e-b24c65aa66870d96ab2d-9dd2-4d2c-a45e-b24c65aa6687 | |
cdbeb35b-87ea-499f-b545-defbae091b57cdbeb35b-87ea-499f-b545-defbae091b57 | a90a303c-8a14-4207-8f35-d8ea94ca45bea90a303c-8a14-4207-8f35-d8ea94ca45be | |
4fcb4598-9a31-4614-903c-0c67c286da8c4fcb4598-9a31-4614-903c-0c67c286da8c | 97aafea1-59ff-4312-b06b-08f42187872f97aafea1-59ff-4312-b06b-08f42187872f | |
2dfdef64-62a3-4950-a130-96b5b1083b5a2dfdef64-62a3-4950-a130-96b5b1083b5a | 0fb7f3da-5e28-4f09-a000-e62eb41592df0fb7f3da-5e28-4f09-a000-e62eb41592df |
将一个表中所有的区移至另一个表,删除特定区Move all extents from one table to another, drop specific extent
从一个特定表 (MyTable1
) 中将所有区移至表 MyOtherTable
,并删除 MyOtherTable
中的特定区(按其 ID):Move all extents from one specific tavle (MyTable1
) to table MyOtherTable
, and drop a specific extent in MyOtherTable
, by its ID:
.replace extents in table MyOtherTable <|
{
print ExtentId = "2cca5844-8f0d-454e-bdad-299e978be5df"
},
{
.show table MyTable1 extents
}
.replace extents in table MyOtherTable <|
{
.show table MyOtherTable extents
| where ExtentId == guid(2cca5844-8f0d-454e-bdad-299e978be5df)
},
{
.show table MyTable1 extents
}
实现幂等逻辑Implement an idempotent logic
实现幂等逻辑,以便 Kusto 仅在有区要从表 t_source
移至表 t_dest
的情况下才从表 t_dest
中删除区:Implement an idempotent logic so that Kusto drops extents from table t_dest
only if there are extents to move from table t_source
to table t_dest
:
.replace async extents in table t_dest <|
{
let any_extents_to_move = toscalar(
t_source
| where extent_tags() has 'drop-by:blue'
| summarize count() > 0
);
let extents_to_drop =
t_dest
| where any_extents_to_move and extent_tags() has 'drop-by:blue'
| summarize by ExtentId = extent_id()
;
extents_to_drop
},
{
let extents_to_move =
t_source
| where extent_tags() has 'drop-by:blue'
| summarize by ExtentId = extent_id()
;
extents_to_move
}