From e8c4bb34409f0a2e1856d9aad14a2a64f5999f84 Mon Sep 17 00:00:00 2001 From: liuxian9 Date: Tue, 14 Jul 2015 21:28:27 -0700 Subject: [PATCH 1/2] Added examples for MediaScan and MediaOptimize. --- CMakeLists.txt | 6 ++-- src/media_optimize_blocking.cc | 61 ++++++++++++++++++++++++++++++++++ src/media_scan_blocking.cc | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/media_optimize_blocking.cc create mode 100644 src/media_scan_blocking.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 67ad398..4408adb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(GENERATED_SOURCES_PATH ${kinetic_cpp_client_SOURCE_DIR}/src/main/generated) include(ExternalProject) -option(USE_LOCAL_KINETIC_CLIENT "Uses the kinetic client at the KINETIC_CLIENT_PATH variable instead of downloading library from Git" off) +option(USE_LOCAL_KINETIC_CLIENT "Uses the kinetic client at the KINETIC_CLIENT_PATH variable instead of downloading library from Git" on) if(USE_LOCAL_KINETIC_CLIENT) else(USE_LOCAL_KINETIC_CLIENT) set(KINETIC_CLIENT_PATH "${CMAKE_BINARY_DIR}/vendor/src/kinetic_cpp_client") @@ -17,7 +17,7 @@ else(USE_LOCAL_KINETIC_CLIENT) kinetic_cpp_client PREFIX "vendor" GIT_REPOSITORY "https://github.com/Seagate/kinetic-cpp-client.git" - GIT_TAG "0.1.1" + GIT_TAG "develop" BUILD_IN_SOURCE 1 INSTALL_COMMAND "" ) @@ -78,3 +78,5 @@ add_example_target(firmware_update false) add_example_target(write_file_blocking_threads false) add_example_target(dump_keyspace false) add_example_target(copydrive false) +add_example_target(media_scan_blocking true) +add_example_target(media_optimize_blocking true) diff --git a/src/media_optimize_blocking.cc b/src/media_optimize_blocking.cc new file mode 100644 index 0000000..6bd7ae1 --- /dev/null +++ b/src/media_optimize_blocking.cc @@ -0,0 +1,61 @@ +/* + * kinetic-cpp-examples + * Copyright (C) 2014 Seagate Technology. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +// This allows changing a drive's cluster version +#include + +#include "kinetic/kinetic.h" +#include "gflags/gflags.h" + +using com::seagate::kinetic::client::proto::Command_Algorithm_SHA1; +using kinetic::Status; +using kinetic::KineticRecord; +using kinetic::MediaScanRequest; +using kinetic::MediaOptimizeRequest; +using kinetic::RequestPriority; + +using std::unique_ptr; + +DEFINE_string(start_key, "", "MediaOptimize start key"); +DEFINE_string(start_key_inclusive, "true", "MediaOptimize start key inclusive"); +DEFINE_string(end_key, "", "MediaOptimize end key"); +DEFINE_string(end_key_inclusive, "true", "MediaOptimize end key inclusive"); + +int example_main( + std::shared_ptr nonblocking_connection, + std::shared_ptr blocking_connection, + int argc, char** argv) { + //media optimize + MediaOptimizeRequest media_optimize_request; + media_optimize_request.start_key = FLAGS_start_key; + media_optimize_request.end_key = FLAGS_end_key; + media_optimize_request.start_key_inclusive = FLAGS_start_key_inclusive.compare("true") == 0; + media_optimize_request.end_key_inclusive = FLAGS_end_key_inclusive.compare("true") == 0; + + RequestPriority priority = RequestPriority::Priority_NORMAL; + kinetic::KineticStatus status = blocking_connection->MediaOptimize( + media_optimize_request, priority); + std::string result = status.ok() ? "success" : "failure"; + printf("Media optimize %s ~ %s return %s\n", + media_optimize_request.start_key.c_str(), + media_optimize_request.end_key.c_str(), result.c_str()); + + return 0; +} diff --git a/src/media_scan_blocking.cc b/src/media_scan_blocking.cc new file mode 100644 index 0000000..93b8158 --- /dev/null +++ b/src/media_scan_blocking.cc @@ -0,0 +1,60 @@ +/* + * kinetic-cpp-examples + * Copyright (C) 2014 Seagate Technology. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +// This allows changing a drive's cluster version +#include + +#include "kinetic/kinetic.h" +#include "gflags/gflags.h" + +using com::seagate::kinetic::client::proto::Command_Algorithm_SHA1; +using kinetic::Status; +using kinetic::KineticRecord; +using kinetic::MediaScanRequest; +using kinetic::MediaOptimizeRequest; +using kinetic::RequestPriority; + +using std::unique_ptr; + +DEFINE_string(start_key, "", "MediaScan start key"); +DEFINE_string(start_key_inclusive, "true", "MediaScan start key inclusive"); +DEFINE_string(end_key, "", "MediaScan end key"); +DEFINE_string(end_key_inclusive, "true", "MediaScan end key inclusive"); + +int example_main( + std::shared_ptr nonblocking_connection, + std::shared_ptr blocking_connection, + int argc, char** argv) { + //media scan + MediaScanRequest media_scan_request; + media_scan_request.start_key = FLAGS_start_key; + media_scan_request.end_key = FLAGS_end_key; + media_scan_request.start_key_inclusive = FLAGS_start_key_inclusive.compare("true") == 0; + media_scan_request.end_key_inclusive = FLAGS_end_key_inclusive.compare("true") == 0; + + RequestPriority priority = RequestPriority::Priority_NORMAL; + kinetic::KineticStatus status = blocking_connection->MediaScan( + media_scan_request, priority); + std::string result = status.ok() ? "success" : "failure"; + printf("Media scan %s ~ %s return %s\n", media_scan_request.start_key.c_str(), + media_scan_request.end_key.c_str(), result.c_str()); + + return 0; +} From 4ac288b05f89641f39a6eda32e19484bd3ab89ff Mon Sep 17 00:00:00 2001 From: liuxian9 Date: Tue, 14 Jul 2015 21:35:18 -0700 Subject: [PATCH 2/2] Updated readme for MediaScan and MediaOptimize example. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index b870551..537d417 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,18 @@ Changes the cluster version and verifies that requests with the old cluster vers Allows changing a drive's PIN. For instance: ./setpin -host 127.1 -port 8123 -new_pin 1234 -old_pin 5678 + +`media_scan_blocking` (see `src/media_scan_blocking.cc`) +-------- +Performs media scan with the specified range and priority. For instance: + + ./media_scan_blocking -host 127.1 -port 8123 -start_key key000 -end_key key999 -start_key_inclusive true -end_key_inclusive true + +`media_optimize_blocking` (see `src/media_optimize_blocking.cc`) +-------- +Performs media optimize with the specified range and priority. For instance: + + ./media_optimize_blocking -host 127.1 -port 8123 -start_key key000 -end_key key999 -start_key_inclusive true -end_key_inclusive true Object store examples ---------------------