Hello Riza Suminto, Jason Fehr, [email protected], Sai Hemanth 
Gantasala, Michael Smith, Csaba Ringhofer, Steve Carlin, Impala Public Jenkins,

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/20131

to look at the new patch set (#36).

Change subject: IMPALA-12152: Add query options to wait for HMS events sync up
......................................................................

IMPALA-12152: Add query options to wait for HMS events sync up

It's a common scenario to run Impala queries after the dependent
external changes are done. E.g. running COMPUTE STATS on a table after
Hive/Spark jobs ingest some new data to it. Currently, it's unsafe to
run the Impala queries immediately after the Hive/Spark jobs finish
since EventProcessor might have a long lag in applying the HMS events.
Note that running REFRESH/INVALIDATE on the table can also solve the
problem. But one of the motivation of EventProcessor is to get rid of
such Impala specific commands.

This patch adds a mechanism to let query planning wait until the
metadata is synced up. Two new query options are added:
 - SYNC_HMS_EVENTS_WAIT_TIME_S configures the timeout in seconds for
   waiting. It's 0 by default, which disables the waiting mechanism.
 - SYNC_HMS_EVENTS_STRICT_MODE controls the behavior if we can't wait
   for metadata to be synced up, e.g. when the waiting times out or
   EventProcessor is in ERROR state. It defaults to false (non-strict
   mode). In the strict mode, coordinator will fail the query. In the
   non-strict mode, coordinator will start planning with a warning
   message in profile (and in client outputs if the client consumes the
   get_log results, e.g. in impala-shell).

Example usage - query the table after inserting into dynamic partitions
in Hive. We don't know what partitions are modified so running REFRESH
in Impala is inefficient since it reloads all partitions.
  hive> insert into tbl partition(p) select * from tbl2;
  impala> set sync_hms_events_wait_time_s=300;
  impala> select * from tbl;
With this new feature, let catalogd reload the updated partitions based
on HMS events, which is more efficient than REFRESH. The wait time can
be set to the largest lag of event processing that has been observed in
the cluster. Note the lag of event processing is shown as the "Lag time"
in the /events page of catalogd WebUI and "events-processor.lag-time" in
the /metrics page. Users can monitor it to get a sense of the lag.

Some timeline items are added in query profile for this waiting
mechanism, e.g.
A succeeded wait:
    Query Compilation: 937.279ms
       - Synced events from Metastore: 909.162ms (909.162ms)
       - Metadata of all 1 tables cached: 911.005ms (1.843ms)
       - Analysis finished: 919.600ms (8.595ms)

A failed wait:
    Query Compilation: 1s321ms
       - Continuing without syncing Metastore events: 40.883ms (40.883ms)
       - Metadata load started: 41.618ms (735.633us)

Added a histogram metric, impala-server.wait-for-hms-event-durations-ms,
to track the duration of this waiting.

--------
Implementation

A new catalogd RPC, WaitForHmsEvent, is added to CatalogService API so
that coordinator can wait until catalogd processes the latest event when
this RPC is triggered. Query planning starts or fails after this RPC
returns. The RPC request contains the potential dbs/tables that are
required by the query. Catalogd records the latest event id when it
receives this RPC. When the last synced event id reaches this, catalogd
returns the catalog updates to the coordinator in the RPC response.
Before that, the RPC thread is in a waiting loop that sleeps in a
configurable interval. It's configured by a hidden flag,
hms_event_sync_sleep_interval_ms (defaults to 100).

Entry-point functions
 - Frontend#waitForHmsEvents()
 - CatalogServiceCatalog#waitForHmsEvent()

Some statements don't need to wait for HMS events, e.g. CREATE/DROP ROLE
statements. This patch adds an overrided method, requiresHmsMetadata(),
in each Statement to mark whether they can skip HMS event sync.

Test side changes:
 - Some test codes use EventProcessorUtils.wait_for_event_processing()
   to wait for HMS events being synced up before running a query. Now
   they are updated to just use these new query options in the query.
 - Note that we still need wait_for_event_processing() in test codes
   that verify metrics after HMS events are synced up.

--------
Limitation

Currently, UPDATE_TBL_COL_STAT_EVENT, UPDATE_PART_COL_STAT_EVENT,
OPEN_TXN events are ignored by the event processor. If the latest event
happens to be in these types and there are no more other events, the
last synced event id can never reach the latest event id. We need to fix
last synced event id to also consider ignored events (IMPALA-13623).

The current implementation waits for the event id when the
WaitForHmsEvent RPC is received at catalogd side. We can improve it
by leveraging HIVE-27499 to efficiently detect whether the given
dbs/tables have unsynced events and just wait for the *largest* id
of them. Dbs/tables without unsynced events don't need to block query
planning. However, this only works for non-transactional tables.
Transactional tables might be modified by COMMIT_TXN or ABORT_TXN events
which don't have the table names. So even with HIVE-27499, we can't
determine whether a transactional table has pending events. IMPALA-13684
will target on improving this on non-transactional tables.

Tests
 - Add test to verify planning waits until catalogd is synced with HMS
   changes.
 - Add test on the error handling when HMS event processing is disabled

Change-Id: I36ac941bb2c2217b09fcfa2eb567b011b38efa2a
---
M be/src/catalog/catalog-server.cc
M be/src/catalog/catalog-service-client-wrapper.h
M be/src/catalog/catalog.cc
M be/src/catalog/catalog.h
M be/src/exec/catalog-op-executor.cc
M be/src/exec/catalog-op-executor.h
M be/src/service/fe-support.cc
M be/src/service/impala-server.cc
M be/src/service/query-options.cc
M be/src/service/query-options.h
M be/src/util/backend-gflag-util.cc
M be/src/util/impalad-metrics.cc
M be/src/util/impalad-metrics.h
M common/thrift/BackendGflags.thrift
M common/thrift/CatalogService.thrift
M common/thrift/ImpalaService.thrift
M common/thrift/Query.thrift
M common/thrift/metrics.json
M fe/src/main/java/org/apache/impala/analysis/AdminFnStmt.java
M fe/src/main/java/org/apache/impala/analysis/AlterDbStmt.java
M fe/src/main/java/org/apache/impala/analysis/Analyzer.java
M fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java
M fe/src/main/java/org/apache/impala/analysis/CreateDropRoleStmt.java
M fe/src/main/java/org/apache/impala/analysis/DescribeDbStmt.java
M fe/src/main/java/org/apache/impala/analysis/DropDbStmt.java
M fe/src/main/java/org/apache/impala/analysis/GrantRevokeRoleStmt.java
M fe/src/main/java/org/apache/impala/analysis/SetStmt.java
M fe/src/main/java/org/apache/impala/analysis/ShowDataSrcsStmt.java
M fe/src/main/java/org/apache/impala/analysis/ShowFunctionsStmt.java
M fe/src/main/java/org/apache/impala/analysis/ShowGrantPrincipalStmt.java
M fe/src/main/java/org/apache/impala/analysis/ShowRolesStmt.java
M fe/src/main/java/org/apache/impala/analysis/ShowTablesOrViewsStmt.java
M fe/src/main/java/org/apache/impala/analysis/StatementBase.java
M fe/src/main/java/org/apache/impala/catalog/Catalog.java
M fe/src/main/java/org/apache/impala/catalog/CatalogDeltaLog.java
M fe/src/main/java/org/apache/impala/catalog/CatalogServiceCatalog.java
M fe/src/main/java/org/apache/impala/catalog/ImpaladCatalog.java
M fe/src/main/java/org/apache/impala/catalog/events/ExternalEventsProcessor.java
M 
fe/src/main/java/org/apache/impala/catalog/events/MetastoreEventsProcessor.java
M fe/src/main/java/org/apache/impala/service/FeSupport.java
M fe/src/main/java/org/apache/impala/service/Frontend.java
M fe/src/main/java/org/apache/impala/service/JniCatalog.java
M tests/common/impala_test_suite.py
M tests/custom_cluster/test_event_processing_error.py
M tests/custom_cluster/test_events_custom_configs.py
M tests/custom_cluster/test_hive_parquet_codec_interop.py
M tests/custom_cluster/test_kudu.py
M tests/metadata/test_event_processing.py
M tests/metadata/test_event_processing_base.py
M tests/metadata/test_metadata_query_statements.py
M tests/query_test/test_hive_codec_interop.py
51 files changed, 1,140 insertions(+), 221 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/31/20131/36
--
To view, visit http://gerrit.cloudera.org:8080/20131
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I36ac941bb2c2217b09fcfa2eb567b011b38efa2a
Gerrit-Change-Number: 20131
Gerrit-PatchSet: 36
Gerrit-Owner: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Anonymous Coward <[email protected]>
Gerrit-Reviewer: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>
Gerrit-Reviewer: Michael Smith <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Riza Suminto <[email protected]>
Gerrit-Reviewer: Sai Hemanth Gantasala <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>

Reply via email to