Files
impala/tests/custom_cluster/test_concurrent_kudu_create.py
stiga-huang 3b8609f400 IMPALA-9289: Fix flakiness in TestConcurrentKuduCreate
The test uses a thread pool of 3 slots to run 3 concurrent CreateTable
statements. Each thread creates a client and closes it at the end of the
task(run_create_table_if_not_exists). The first 2 thread tasks start at
the same time. Then after one second, the 3rd thread task starts.
Ideally the 3 tasks should be executed in 3 different threads of the
thread pool. However, if any of the first 2 tasks finish in 1s, the 3rd
task could be executed by reusing the thread. Since the client in the
thread is closed, the task fails.

This patch removes the close operation at the end of the task.
Connection of the thread can be reused and will be closed when the
thread terminates.

Also fix the same problem in test_concurrent_ddls.py.

Tests:
 - Run test_concurrent_ddls.py and test_concurrent_kudu_create.py. In
   the logs of impalad, observe that connections are being reused and
   closed at the end of the tests.

Change-Id: Idefba98ecd65efbd47b1618291330795ef13b910
Reviewed-on: http://gerrit.cloudera.org:8080/15151
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2020-02-05 06:23:44 +00:00

66 lines
2.4 KiB
Python

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import pytest
import threading
import time
from multiprocessing.pool import ThreadPool
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
TBL_NAME = "test_concurrent_kudu_create"
class TestConcurrentKuduCreate(CustomClusterTestSuite):
"""Test concurrent create kudu managed table"""
@pytest.mark.execute_serially
def test_concurrent_create_kudu_table(self, unique_database):
table_name = unique_database + "." + TBL_NAME
test_self = self
class ThreadLocalClient(threading.local):
def __init__(self):
self.client = test_self.create_impala_client()
tls = ThreadLocalClient()
def run_create_table_if_not_exists():
self.execute_query_expect_success(
tls.client, "create table if not exists %s "
"(id int, primary key(id)) stored as kudu" % table_name)
# Drop table before run test if exists
self.execute_query("drop table if exists %s" % table_name)
NUM_ITERS = 20
pool = ThreadPool(processes=3)
for i in xrange(NUM_ITERS):
# Run several commands by specific time interval to reproduce this bug
r1 = pool.apply_async(run_create_table_if_not_exists)
r2 = pool.apply_async(run_create_table_if_not_exists)
# Sleep to make race conflict happens in different places
time.sleep(1)
r3 = pool.apply_async(run_create_table_if_not_exists)
r1.get()
r2.get()
r3.get()
# If hit IMPALA-8984, this query would be failed due to table been deleted in kudu
self.execute_query_expect_success(tls.client, "select * from %s" % table_name)
self.execute_query("drop table if exists %s" % table_name)
pool.terminate()