You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/03/09 16:59:43 UTC

[1/2] impala git commit: IMPALA-6500: gracefully handle invalid sched_getcpu() values

Repository: impala
Updated Branches:
  refs/heads/2.x 0fd962f8d -> eda1f33cd


IMPALA-6500: gracefully handle invalid sched_getcpu() values

It appears that in some cases (probably under virtualization) we can get
out-of-range values returned from this function. Handle that case by
warning and modding the value back into range.

Testing:
Manually modified the function to inject a bad CPU ID. Verified that it
logged the warning as expected.

Added a backend test to exercise the code path. In the process,
repurpose perf-counters-test and delete some dead code that it
referenced.

Change-Id: I5a118953c175b0aa13762ad11dccce01a4c70032
Reviewed-on: http://gerrit.cloudera.org:8080/9544
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/eda1f33c
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/eda1f33c
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/eda1f33c

Branch: refs/heads/2.x
Commit: eda1f33cda9a07883d376207d3a3e628c945a928
Parents: d03fdb5
Author: Tim Armstrong <ta...@cloudera.com>
Authored: Wed Mar 7 14:52:21 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Fri Mar 9 07:44:44 2018 +0000

----------------------------------------------------------------------
 be/src/testutil/cpu-util.h        |  13 +-
 be/src/util/CMakeLists.txt        |   4 +-
 be/src/util/cpu-info.cc           |  17 +-
 be/src/util/perf-counters-test.cc |  66 -----
 be/src/util/perf-counters.cc      | 431 ---------------------------------
 be/src/util/perf-counters.h       | 143 -----------
 be/src/util/sys-info-test.cc      |  68 ++++++
 7 files changed, 95 insertions(+), 647 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/testutil/cpu-util.h
----------------------------------------------------------------------
diff --git a/be/src/testutil/cpu-util.h b/be/src/testutil/cpu-util.h
index d465c52..a995a8e 100644
--- a/be/src/testutil/cpu-util.h
+++ b/be/src/testutil/cpu-util.h
@@ -30,14 +30,15 @@ namespace impala {
 class CpuTestUtil {
  public:
   /// Set the thread affinity so that it always runs on 'core'. Fail the test if
-  /// unsuccessful.
-  static void PinToCore(int core) {
+  /// unsuccessful. If 'validate_current_cpu' is true, checks that
+  /// CpuInfo::GetCurrentCore() returns 'core'.
+  static void PinToCore(int core, bool validate_current_cpu = true) {
     cpu_set_t cpuset;
     CPU_ZERO(&cpuset);
     CPU_SET(core, &cpuset);
     ASSERT_EQ(0, pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset))
         << core;
-    ASSERT_EQ(core, CpuInfo::GetCurrentCore());
+    if (validate_current_cpu) ASSERT_EQ(core, CpuInfo::GetCurrentCore());
   }
 
   /// Reset the thread affinity of the current thread to all cores.
@@ -68,6 +69,12 @@ class CpuTestUtil {
     CpuInfo::InitFakeNumaForTest(num_nodes, core_to_node);
     LOG(INFO) << CpuInfo::DebugString();
   }
+
+  /// Set CpuInfo::max_num_cores_ to 'max_num_cores'. The caller is responsible for
+  /// resetting it to its original value.
+  static void SetMaxNumCores(int max_num_cores) {
+    CpuInfo::max_num_cores_ = max_num_cores;
+  }
 };
 }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/be/src/util/CMakeLists.txt b/be/src/util/CMakeLists.txt
index c9e0f3c..546c1c0 100644
--- a/be/src/util/CMakeLists.txt
+++ b/be/src/util/CMakeLists.txt
@@ -68,8 +68,6 @@ add_library(Util
   path-builder.cc
   periodic-counter-updater
   pprof-path-handlers.cc
-# TODO: not supported on RHEL 5
-#  perf-counters.cc
   progress-updater.cc
   process-state-info.cc
   redactor.cc
@@ -128,7 +126,6 @@ ADD_BE_TEST(metrics-test)
 ADD_BE_TEST(min-max-filter-test)
 ADD_BE_TEST(openssl-util-test)
 ADD_BE_TEST(parse-util-test)
-#ADD_BE_TEST(perf-counters-test)
 ADD_BE_TEST(pretty-printer-test)
 ADD_BE_TEST(proc-info-test)
 ADD_BE_TEST(promise-test)
@@ -139,6 +136,7 @@ ADD_BE_TEST(rle-test)
 ADD_BE_TEST(runtime-profile-test)
 ADD_BE_TEST(string-parser-test)
 ADD_BE_TEST(symbols-util-test)
+ADD_BE_TEST(sys-info-test)
 ADD_BE_TEST(thread-pool-test)
 ADD_BE_TEST(time-test)
 ADD_BE_TEST(uid-util-test)

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/cpu-info.cc
----------------------------------------------------------------------
diff --git a/be/src/util/cpu-info.cc b/be/src/util/cpu-info.cc
index 570e677..815e0d5 100644
--- a/be/src/util/cpu-info.cc
+++ b/be/src/util/cpu-info.cc
@@ -290,7 +290,22 @@ int CpuInfo::GetCurrentCore() {
 #ifdef HAVE_SCHED_GETCPU
   int cpu = sched_getcpu();
   // The syscall may not be supported even if the function exists.
-  return cpu == -1 ? 0 : cpu;
+  if (UNLIKELY(cpu < 0)) return 0;
+  if (UNLIKELY(cpu >= max_num_cores_)) {
+    // IMPALA-6595: on some systems it appears that sched_getcpu() can return
+    // out-of-range CPU ids. We need to avoid returning bogus values from this function,
+    // but should warn the user that something weird is happening.
+    const int MAX_WARNINGS = 20;
+    LOG_FIRST_N(WARNING, MAX_WARNINGS)
+      << "sched_getcpu() returned an out-of-range CPU identifier '" << cpu << "'. "
+      << "The OS originally reported a maximum of " << max_num_cores_ << " online cores. "
+      << "Performance may be negatively affected. This may happen if virtualization "
+      << "software incorrectly virtualizes certain instructions. See IMPALA-6595 for "
+      << "more information. These warnings will stop after " << MAX_WARNINGS << " "
+      << "occurrences.";
+    return cpu % max_num_cores_;
+  }
+  return cpu;
 #else
   return 0;
 #endif

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/perf-counters-test.cc
----------------------------------------------------------------------
diff --git a/be/src/util/perf-counters-test.cc b/be/src/util/perf-counters-test.cc
deleted file mode 100644
index 3c0120f..0000000
--- a/be/src/util/perf-counters-test.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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.
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <iostream>
-
-#include "testutil/gtest-util.h"
-#include "util/disk-info.h"
-#include "util/perf-counters.h"
-
-#include "common/names.h"
-
-namespace impala {
-
-TEST(PerfCounterTest, Basic) {
-  PerfCounters counters;
-  EXPECT_TRUE(counters.AddDefaultCounters());
-
-  counters.Snapshot("Before");
-  double result = 0;
-  for (int i = 0; i < 1000000; i++) {
-    double d1 = rand() / (double) RAND_MAX;
-    double d2 = rand() / (double) RAND_MAX;
-    result = d1*d1 + d2*d2;
-  }
-  counters.Snapshot("After");
-
-  for (int i = 0; i < 1000000; i++) {
-    double d1 = rand() / (double) RAND_MAX;
-    double d2 = rand() / (double) RAND_MAX;
-    result = d1*d1 + d2*d2;
-  }
-  counters.Snapshot("After2");
-  counters.PrettyPrint(&cout);
-}
-
-TEST(CpuInfoTest, Basic) {
-  cout << CpuInfo::DebugString();
-}
-
-TEST(DiskInfoTest, Basic) {
-  cout << DiskInfo::DebugString();
-  cout << "Device name for disk 0: " << DiskInfo::device_name(0) << endl;
-
-  int disk_id_home_dir = DiskInfo::disk_id("/home");
-  cout << "Device name for '/home': " << DiskInfo::device_name(disk_id_home_dir) << endl;
-}
-
-}
-
-IMPALA_TEST_MAIN();

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/perf-counters.cc
----------------------------------------------------------------------
diff --git a/be/src/util/perf-counters.cc b/be/src/util/perf-counters.cc
deleted file mode 100644
index 296968e..0000000
--- a/be/src/util/perf-counters.cc
+++ /dev/null
@@ -1,431 +0,0 @@
-// 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.
-
-// TODO: "Performance Counters for Linux" is not supported in Linux < 2.6.31.
-//       This file will not compile under RHEL 5 or any of it's derivitives.
-
-#include "util/perf-counters.h"
-#include "util/debug-util.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <fstream>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-
-#include <sys/syscall.h>
-#include <linux/perf_event.h>
-
-#define COUNTER_SIZE (sizeof(void*))
-#define BUFFER_SIZE 256
-#define PRETTY_PRINT_WIDTH 13
-
-#include "common/names.h"
-
-namespace impala {
-
-// This is the order of the counters in /proc/self/io
-enum PERF_IO_IDX {
-  PROC_IO_READ = 0,
-  PROC_IO_WRITE,
-  PROC_IO_SYS_RREAD,
-  PROC_IO_SYS_WRITE,
-  PROC_IO_DISK_READ,
-  PROC_IO_DISK_WRITE,
-  PROC_IO_CANCELLED_WRITE,
-  PROC_IO_LAST_COUNTER,
-};
-
-// Wrapper around sys call.  This syscall is hard to use and this is how it is recommended
-// to be used.
-static inline int sys_perf_event_open(
-    struct perf_event_attr* attr,
-    pid_t pid, int cpu, int group_fd,
-    unsigned long flags) {
-  attr->size = sizeof(*attr);
-  return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
-}
-
-// Remap PerfCounters::Counter to Linux kernel enums
-static bool InitEventAttr(perf_event_attr* attr, PerfCounters::Counter counter) {
-  memset(attr, 0, sizeof(perf_event_attr));
-
-  switch (counter) {
-    case PerfCounters::PERF_COUNTER_SW_CPU_CLOCK:
-      attr->type = PERF_TYPE_SOFTWARE;
-      attr->config = PERF_COUNT_SW_CPU_CLOCK;
-      break;
-    case PerfCounters::PERF_COUNTER_SW_PAGE_FAULTS:
-      attr->type = PERF_TYPE_SOFTWARE;
-      attr->config = PERF_COUNT_SW_PAGE_FAULTS;
-      break;
-    case PerfCounters::PERF_COUNTER_SW_CONTEXT_SWITCHES:
-      attr->type = PERF_TYPE_SOFTWARE;
-      attr->config = PERF_COUNT_SW_PAGE_FAULTS;
-      break;
-    case PerfCounters::PERF_COUNTER_SW_CPU_MIGRATIONS:
-      attr->type = PERF_TYPE_SOFTWARE;
-      attr->config = PERF_COUNT_SW_CPU_MIGRATIONS;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_CPU_CYCLES:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_CPU_CYCLES;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_INSTRUCTIONS:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_INSTRUCTIONS;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_CACHE_HIT:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_CACHE_REFERENCES;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_CACHE_MISSES:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_CACHE_MISSES;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_BRANCHES:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_BRANCH_MISSES:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_BRANCH_MISSES;
-      break;
-    case PerfCounters::PERF_COUNTER_HW_BUS_CYCLES:
-      attr->type = PERF_TYPE_HARDWARE;
-      attr->config = PERF_COUNT_HW_BUS_CYCLES;
-      break;
-    default:
-      return false;
-  }
-
-  return true;
-}
-
-static string GetCounterName(PerfCounters::Counter counter) {
-  switch (counter) {
-    case PerfCounters::PERF_COUNTER_SW_CPU_CLOCK:
-      return "CPUTime";
-    case PerfCounters::PERF_COUNTER_SW_PAGE_FAULTS:
-      return "PageFaults";
-    case PerfCounters::PERF_COUNTER_SW_CONTEXT_SWITCHES:
-      return "ContextSwitches";
-    case PerfCounters::PERF_COUNTER_SW_CPU_MIGRATIONS:
-      return "CPUMigrations";
-    case PerfCounters::PERF_COUNTER_HW_CPU_CYCLES:
-      return "HWCycles";
-    case PerfCounters::PERF_COUNTER_HW_INSTRUCTIONS:
-      return "Instructions";
-    case PerfCounters::PERF_COUNTER_HW_CACHE_HIT:
-      return "CacheHit";
-    case PerfCounters::PERF_COUNTER_HW_CACHE_MISSES:
-      return "CacheMiss";
-    case PerfCounters::PERF_COUNTER_HW_BRANCHES:
-      return "Branches";
-    case PerfCounters::PERF_COUNTER_HW_BRANCH_MISSES:
-      return "BranchMiss";
-    case PerfCounters::PERF_COUNTER_HW_BUS_CYCLES:
-      return "BusCycles";
-    case PerfCounters::PERF_COUNTER_VM_USAGE:
-      return "VmUsage";
-    case PerfCounters::PERF_COUNTER_VM_PEAK_USAGE:
-      return "PeakVmUsage";
-    case PerfCounters::PERF_COUNTER_RESIDENT_SET_SIZE:
-      return "WorkingSet";
-    case PerfCounters::PERF_COUNTER_BYTES_READ:
-      return "BytesRead";
-    case PerfCounters::PERF_COUNTER_BYTES_WRITE:
-      return "BytesWritten";
-    case PerfCounters::PERF_COUNTER_DISK_READ:
-      return "DiskRead";
-    case PerfCounters::PERF_COUNTER_DISK_WRITE:
-      return "DiskWrite";
-    default:
-      return "";
-  }
-}
-
-bool PerfCounters::InitSysCounter(Counter counter) {
-  CounterData data;
-  data.counter = counter;
-  data.source = PerfCounters::SYS_PERF_COUNTER;
-  data.fd = -1;
-  perf_event_attr attr;
-  if (!InitEventAttr(&attr, counter)) {
-    return false;
-  }
-  int fd = sys_perf_event_open(&attr, getpid(), -1, group_fd_, 0);
-  if (fd < 0) {
-    return false;
-  }
-  if (group_fd_ == -1) {
-    group_fd_ = fd;
-  }
-  data.fd = fd;
-
-  if (counter == PERF_COUNTER_SW_CPU_CLOCK) {
-    data.type = TUnit::TIME_NS;
-  } else {
-    data.type = TUnit::UNIT;
-  }
-  counters_.push_back(data);
-  return true;
-}
-
-bool PerfCounters::InitProcSelfIOCounter(Counter counter) {
-  CounterData data;
-  data.counter = counter;
-  data.source = PerfCounters::PROC_SELF_IO;
-  data.type = TUnit::BYTES;
-
-  switch (counter) {
-    case PerfCounters::PERF_COUNTER_BYTES_READ:
-      data.proc_io_line_number = PROC_IO_READ;
-      break;
-    case PerfCounters::PERF_COUNTER_BYTES_WRITE:
-      data.proc_io_line_number = PROC_IO_WRITE;
-      break;
-    case PerfCounters::PERF_COUNTER_DISK_READ:
-      data.proc_io_line_number = PROC_IO_DISK_READ;
-      break;
-    case PerfCounters::PERF_COUNTER_DISK_WRITE:
-      data.proc_io_line_number = PROC_IO_DISK_WRITE;
-      break;
-    default:
-      return false;
-  }
-  counters_.push_back(data);
-  return true;
-}
-
-bool PerfCounters::InitProcSelfStatusCounter(Counter counter) {
-  CounterData data;
-  data.counter = counter;
-  data.source = PerfCounters::PROC_SELF_STATUS;
-  data.type = TUnit::BYTES;
-
-  switch (counter) {
-    case PerfCounters::PERF_COUNTER_VM_USAGE:
-      data.proc_status_field = "VmSize";
-      break;
-    case PerfCounters::PERF_COUNTER_VM_PEAK_USAGE:
-      data.proc_status_field = "VmPeak";
-      break;
-    case PerfCounters::PERF_COUNTER_RESIDENT_SET_SIZE:
-      data.proc_status_field = "VmRS";
-      break;
-    default:
-      return false;
-  }
-  counters_.push_back(data);
-  return true;
-}
-
-bool PerfCounters::GetSysCounters(vector<int64_t>& buffer) {
-  for (int i = 0; i < counters_.size(); i++) {
-    if (counters_[i].source == SYS_PERF_COUNTER) {
-      int num_bytes = read(counters_[i].fd, &buffer[i], COUNTER_SIZE);
-      if (num_bytes != COUNTER_SIZE) return false;
-      if (counters_[i].type == TUnit::TIME_NS) {
-        buffer[i] /= 1000000;
-      }
-    }
-  }
-  return true;
-}
-
-// Parse out IO counters from /proc/self/io.  The file contains a list of 
-// (name,byte) pairs.
-// For example:
-//    rchar: 210212
-//    wchar: 94
-//    syscr: 118
-//    syscw: 3
-//    read_bytes: 0
-//    write_bytes: 0
-//    cancelled_write_bytes: 0
-bool PerfCounters::GetProcSelfIOCounters(vector<int64_t>& buffer) {
-  ifstream file("/proc/self/io", ios::in);
-  string buf;
-  int64_t values[PROC_IO_LAST_COUNTER];
-
-  for (int i = 0; i < PROC_IO_LAST_COUNTER; ++i) {
-    if (!file) goto end;
-    getline(file, buf);
-    size_t colon = buf.find(':');
-    if (colon == string::npos) goto end;
-    buf = buf.substr(colon + 1);
-    istringstream stream(buf);
-    stream >> values[i];
-  }
-
-  for (int i = 0; i < counters_.size(); ++i) {
-    if (counters_[i].source == PROC_SELF_IO) {
-      buffer[i] = values[counters_[i].proc_io_line_number];
-    }
-  }
-end:
-  if (file.is_open()) file.close();
-  return true;
-}
-
-bool PerfCounters::GetProcSelfStatusCounters(vector<int64_t>& buffer) {
-  ifstream file("/proc/self/status", ios::in);
-  string buf;
-  
-  while (file) {
-    getline(file, buf);
-    for (int i = 0; i < counters_.size(); ++i) {
-      if (counters_[i].source == PROC_SELF_STATUS) {
-        size_t field = buf.find(counters_[i].proc_status_field);
-        if (field == string::npos) continue;
-        size_t colon = field + counters_[i].proc_status_field.size() + 1;
-        buf = buf.substr(colon + 1);
-        istringstream stream(buf);
-        int64_t value;
-        stream >> value;
-        buffer[i] = value * 1024;  // values in file are in kb
-      }
-    }
-  }
-  if (file.is_open()) file.close();
-  return true;
-}
-
-PerfCounters::PerfCounters() : group_fd_(-1) {
-}
-
-// Close all fds for the counters
-PerfCounters::~PerfCounters() {
-  for (int i = 0; i < counters_.size(); ++i) {
-    if (counters_[i].source == SYS_PERF_COUNTER) {
-      close(counters_[i].fd);
-    }
-  }
-}
-
-// Add here the default ones that are most useful
-bool PerfCounters::AddDefaultCounters() {
-  bool result = true;
-  result &= AddCounter(PERF_COUNTER_SW_CPU_CLOCK); 
-  // These hardware ones don't work on a vm, just ignore if they fail
-  // TODO: these don't work reliably and aren't that useful.  Turn them off.
-  //AddCounter(PERF_COUNTER_HW_INSTRUCTIONS);
-  //AddCounter(PERF_COUNTER_HW_CPU_CYCLES);
-  //AddCounter(PERF_COUNTER_HW_BRANCHES);
-  //AddCounter(PERF_COUNTER_HW_BRANCH_MISSES);
-  //AddCounter(PERF_COUNTER_HW_CACHE_MISSES);
-  AddCounter(PERF_COUNTER_VM_USAGE);
-  AddCounter(PERF_COUNTER_VM_PEAK_USAGE);
-  AddCounter(PERF_COUNTER_RESIDENT_SET_SIZE);
-  result &= AddCounter(PERF_COUNTER_DISK_READ);
-  return result;
-}
-
-// Add a specific counter
-bool PerfCounters::AddCounter(Counter counter) {
-  // Ignore if it's already added.
-  for (int i = 0; i < counters_.size(); ++i) {
-    if (counters_[i].counter == counter) {
-      return true;
-    }
-  }
-  bool result = false;
-  switch (counter) {
-    case PerfCounters::PERF_COUNTER_SW_CPU_CLOCK:
-    case PerfCounters::PERF_COUNTER_SW_PAGE_FAULTS:
-    case PerfCounters::PERF_COUNTER_SW_CONTEXT_SWITCHES:
-    case PerfCounters::PERF_COUNTER_SW_CPU_MIGRATIONS:
-    case PerfCounters::PERF_COUNTER_HW_CPU_CYCLES:
-    case PerfCounters::PERF_COUNTER_HW_INSTRUCTIONS:
-    case PerfCounters::PERF_COUNTER_HW_CACHE_HIT:
-    case PerfCounters::PERF_COUNTER_HW_CACHE_MISSES:
-    case PerfCounters::PERF_COUNTER_HW_BRANCHES:
-    case PerfCounters::PERF_COUNTER_HW_BRANCH_MISSES:
-    case PerfCounters::PERF_COUNTER_HW_BUS_CYCLES:
-      result = InitSysCounter(counter);
-      break;
-    case PerfCounters::PERF_COUNTER_BYTES_READ:
-    case PerfCounters::PERF_COUNTER_BYTES_WRITE:
-    case PerfCounters::PERF_COUNTER_DISK_READ:
-    case PerfCounters::PERF_COUNTER_DISK_WRITE:
-      result = InitProcSelfIOCounter(counter);
-      break;
-    case PerfCounters::PERF_COUNTER_VM_USAGE:
-    case PerfCounters::PERF_COUNTER_VM_PEAK_USAGE:
-    case PerfCounters::PERF_COUNTER_RESIDENT_SET_SIZE:
-      result = InitProcSelfStatusCounter(counter);
-      break;
-    default:
-      return false;
-  }
-  if (result) counter_names_.push_back(GetCounterName(counter));
-  return result;
-}
-
-// Query all the counters right now and store the values in results
-void PerfCounters::Snapshot(const string& name) {
-  if (counters_.size() == 0) {
-    return;
-  }
-
-  string fixed_name = name;
-  if (fixed_name.size() == 0) {
-    stringstream ss;
-    ss << snapshots_.size() + 1;
-    fixed_name = ss.str();
-  }
-
-  vector<int64_t> buffer(counters_.size());
-
-  GetSysCounters(buffer);
-  GetProcSelfIOCounters(buffer);
-  GetProcSelfStatusCounters(buffer);
-
-  snapshots_.push_back(buffer);
-  snapshot_names_.push_back(fixed_name);
-}
-
-const vector<int64_t>* PerfCounters::counters(int snapshot) const {
-  if (snapshot < 0 || snapshot >= snapshots_.size()) return NULL;
-  return &snapshots_[snapshot];
-}
-
-void PerfCounters::PrettyPrint(ostream* s) const {
-  ostream& stream = *s;
-  stream << setw(8) << "Snapshot";
-  for (int i = 0; i < counter_names_.size(); ++i) {
-    stream << setw(PRETTY_PRINT_WIDTH) << counter_names_[i];
-  }
-  stream << endl;
-
-  for (int s = 0; s < snapshots_.size(); s++) {
-    stream << setw(8) << snapshot_names_[s];
-    const vector<int64_t>& snapshot = snapshots_[s];
-    for (int i = 0; i < snapshot.size(); ++i) {
-      stream << setw(PRETTY_PRINT_WIDTH) << PrettyPrinter::Print(snapshot[i], counters_[i].type);
-    }
-    stream << endl;
-  }
-  stream << endl;
-}
-
-}
-

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/perf-counters.h
----------------------------------------------------------------------
diff --git a/be/src/util/perf-counters.h b/be/src/util/perf-counters.h
deleted file mode 100644
index 8e061bb..0000000
--- a/be/src/util/perf-counters.h
+++ /dev/null
@@ -1,143 +0,0 @@
-// 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.
-
-
-#ifndef IMPALA_UTIL_PERF_COUNTER_H
-#define IMPALA_UTIL_PERF_COUNTER_H
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include "util/debug-util.h"
-
-/// This is a utility class that aggregates counters from the kernel.  These counters
-/// come from different sources.
-///   - perf counter syscall (/usr/include/linux/perf_event.h")
-///   - /proc/self/io: io stats
-///   - /proc/self/status: memory stats
-/// The complexity here is that all these sources have data in a different and not
-/// easy to get at format.
-//
-/// A typical usage pattern would be:
-///  PerfCounters counters;
-///  counters.AddDefaultCounters();
-///  counters.Snapshot("After Init");
-///  <do your work>
-///  counters.Snapshot("After Work");
-///  counters.PrettyPrint(cout);
-
-namespace impala {
-
-class PerfCounters {
- public:
-  enum Counter {
-    PERF_COUNTER_SW_CPU_CLOCK,
-    PERF_COUNTER_SW_PAGE_FAULTS,
-    PERF_COUNTER_SW_CONTEXT_SWITCHES,
-    PERF_COUNTER_SW_CPU_MIGRATIONS,
-
-    PERF_COUNTER_HW_CPU_CYCLES,
-    PERF_COUNTER_HW_INSTRUCTIONS,
-    PERF_COUNTER_HW_CACHE_HIT,
-    PERF_COUNTER_HW_CACHE_MISSES,
-    PERF_COUNTER_HW_BRANCHES,
-    PERF_COUNTER_HW_BRANCH_MISSES,
-    PERF_COUNTER_HW_BUS_CYCLES,
-
-    PERF_COUNTER_VM_USAGE,
-    PERF_COUNTER_VM_PEAK_USAGE,
-    PERF_COUNTER_RESIDENT_SET_SIZE,
-
-    PERF_COUNTER_BYTES_READ,
-    PERF_COUNTER_BYTES_WRITE,
-    PERF_COUNTER_DISK_READ,
-    PERF_COUNTER_DISK_WRITE,
-  };
-
-  /// Add the 'default' counters as ones to collect.  Returns false if any of those
-  /// counters are not available.
-  /// Counters cannot be added after a snapshot has been taken.
-  bool AddDefaultCounters();
-
-  /// Add a specific counter to watch.  Return false if that counter is not available.
-  /// Counters cannot be added after a snapshot has been taken.
-  bool AddCounter(Counter);
-
-  /// Take a snapshot of all the counters and store it.  The caller can specify a name
-  /// for the snapshot.
-  void Snapshot(const std::string& name = "");
-
-  /// Returns the results of that snapshot
-  const std::vector<int64_t>* counters(int snapshot) const;
-
-  /// Returns readable names for the added counters
-  const std::vector<std::string>* counter_names() const { return &counter_names_; }
-
-  /// Prints out the names and results for all snapshots to 'out'
-  void PrettyPrint(std::ostream* out) const;
-
-  PerfCounters();
-  ~PerfCounters();
-
- private:
-  /// Copy constructor and assignment not allowed
-  PerfCounters(const PerfCounters&);
-  PerfCounters& operator=(const PerfCounters&);
-
-  bool InitSysCounter(Counter counter);
-  bool InitProcSelfIOCounter(Counter counter);
-  bool InitProcSelfStatusCounter(Counter counter);
-
-  bool GetSysCounters(std::vector<int64_t>& snapshot);
-  bool GetProcSelfIOCounters(std::vector<int64_t>& snapshot);
-  bool GetProcSelfStatusCounters(std::vector<int64_t>& snapshot);
-
-  enum DataSource {
-    SYS_PERF_COUNTER,
-    PROC_SELF_IO,
-    PROC_SELF_STATUS,
-  };
-
-  struct CounterData {
-    Counter counter;
-    DataSource source;
-    TUnit::type unit;
-
-    /// DataSource specific data.  This is used to pull the counter values.
-    union {
-      /// For SYS_PERF_COUNTER. File descriptor where the counter value is stored.
-      int fd;
-      /// For PROC_SELF_IO.  Line number from /proc/self/io file with this counter's value
-      int proc_io_line_number;
-    };
-    /// For PROC_SELF_STATUS.  Field name for counter
-    std::string proc_status_field;
-  };
-
-  std::vector<CounterData> counters_;
-  std::vector<std::string> counter_names_;
-  std::vector<std::string> snapshot_names_;
-  std::vector<std::vector<int64_t>> snapshots_;
-  /// System perf counters can be grouped together.  The OS will update all grouped counters
-  /// at the same time.  This is useful to better correlate counter values.
-  int group_fd_;
-};
-
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/impala/blob/eda1f33c/be/src/util/sys-info-test.cc
----------------------------------------------------------------------
diff --git a/be/src/util/sys-info-test.cc b/be/src/util/sys-info-test.cc
new file mode 100644
index 0000000..76409d8
--- /dev/null
+++ b/be/src/util/sys-info-test.cc
@@ -0,0 +1,68 @@
+// 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.
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <iostream>
+
+#include "testutil/cpu-util.h"
+#include "testutil/gtest-util.h"
+#include "util/disk-info.h"
+#include "util/scope-exit-trigger.h"
+
+#include "common/names.h"
+
+namespace impala {
+
+TEST(CpuInfoTest, Basic) {
+  cout << CpuInfo::DebugString();
+}
+
+// Regression test for IMPALA-6500: make sure we map bad return values from
+// sched_getcpu() into the expected range.
+TEST(CpuInfoTest, InvalidSchedGetCpuValue) {
+  cout << CpuInfo::DebugString();
+  int real_max_num_cores = CpuInfo::GetMaxNumCores();
+  const auto reset_state = MakeScopeExitTrigger([real_max_num_cores]() {
+    CpuTestUtil::SetMaxNumCores(real_max_num_cores);
+    CpuTestUtil::ResetAffinity();
+  });
+
+  // Pretend that we only have two cores. If this test is running on a system
+  // with > 2 cores, sched_getcpu() will return out-of-range values..
+  const int FAKE_NUM_CORES = 2;
+  CpuTestUtil::SetMaxNumCores(FAKE_NUM_CORES);
+  for (int core = 0; core < CpuInfo::num_cores(); ++core) {
+    CpuTestUtil::PinToCore(core, false);
+    int reported_core = CpuInfo::GetCurrentCore();
+    // Check that the reported core is within the expected bounds.
+    ASSERT_GE(reported_core, 0);
+    ASSERT_LT(reported_core, FAKE_NUM_CORES);
+  }
+
+}
+
+TEST(DiskInfoTest, Basic) {
+  cout << DiskInfo::DebugString();
+  cout << "Device name for disk 0: " << DiskInfo::device_name(0) << endl;
+
+  int disk_id_home_dir = DiskInfo::disk_id("/home");
+  cout << "Device name for '/home': " << DiskInfo::device_name(disk_id_home_dir) << endl;
+}
+}
+
+IMPALA_TEST_MAIN();


[2/2] impala git commit: IMPALA-6523: [DOCS] Allowed values for PARQUET_FALLBACK_SCHEMA_RESOLUTION

Posted by ta...@apache.org.
IMPALA-6523: [DOCS] Allowed values for PARQUET_FALLBACK_SCHEMA_RESOLUTION

Change-Id: I9ade6a30c62f4899b6801d03430b5fe15e713474
Reviewed-on: http://gerrit.cloudera.org:8080/9536
Reviewed-by: John Russell <jr...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/d03fdb58
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/d03fdb58
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/d03fdb58

Branch: refs/heads/2.x
Commit: d03fdb5844f8987ca4a3c97aaab3971a6027f82b
Parents: 0fd962f
Author: Alex Rodoni <ar...@cloudera.com>
Authored: Wed Mar 7 12:48:43 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Fri Mar 9 07:44:44 2018 +0000

----------------------------------------------------------------------
 ...impala_parquet_fallback_schema_resolution.xml | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/d03fdb58/docs/topics/impala_parquet_fallback_schema_resolution.xml
----------------------------------------------------------------------
diff --git a/docs/topics/impala_parquet_fallback_schema_resolution.xml b/docs/topics/impala_parquet_fallback_schema_resolution.xml
index c9aa617..b661166 100644
--- a/docs/topics/impala_parquet_fallback_schema_resolution.xml
+++ b/docs/topics/impala_parquet_fallback_schema_resolution.xml
@@ -37,23 +37,32 @@ under the License.
 
     <p rev="2.6.0 IMPALA-2835">
       <indexterm audience="hidden">PARQUET_FALLBACK_SCHEMA_RESOLUTION query option</indexterm>
-      Allows Impala to look up columns within Parquet files by column name, rather than column order,
+      The <codeph>PARQUET_FALLBACK_SCHEMA_RESOLUTION</codeph> query option allows Impala to look
+      up columns within Parquet files by column name, rather than column order,
       when necessary.
+      The allowed values are:
+      <ul>
+        <li>
+          POSITION (0)
+        </li>
+        <li>
+          NAME (1)
+        </li>
+      </ul>
     </p>
 
     <p conref="../shared/impala_common.xml#common/usage_notes_blurb"/>
     <p>
       By default, Impala looks up columns within a Parquet file based on
       the order of columns in the table.
-      The <codeph>name</codeph> setting for this option enables behavior for Impala queries
-      similar to the Hive setting <codeph>parquet.column.index.access=false</codeph>.
+      The <codeph>name</codeph> setting for this option enables behavior for
+      Impala queries similar to the Hive setting <codeph>parquet.column.index access=false</codeph>.
       It also allows Impala to query Parquet files created by Hive with the
       <codeph>parquet.column.index.access=false</codeph> setting in effect.
     </p>
 
     <p>
-      <b>Type:</b> integer or string.
-      Allowed values are 0 or <codeph>position</codeph> (default), 1 or <codeph>name</codeph>.
+      <b>Type:</b> integer or string
     </p>
 
     <p conref="../shared/impala_common.xml#common/added_in_260"/>