You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sh...@apache.org on 2019/01/06 11:53:27 UTC

[arrow] branch master updated: ARROW-4161: [GLib] Add PlasmaClientOptions

This is an automated email from the ASF dual-hosted git repository.

shiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 601498f  ARROW-4161: [GLib] Add PlasmaClientOptions
601498f is described below

commit 601498f7169f2340b393bccba1d0a0e0b65d1562
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Sun Jan 6 20:53:13 2019 +0900

    ARROW-4161: [GLib] Add PlasmaClientOptions
    
    Author: Kouhei Sutou <ko...@clear-code.com>
    
    Closes #3315 from kou/glib-plasma-client-new-options and squashes the following commits:
    
    73eff12a <Kouhei Sutou>  Add support for Plasma::ClientOptions
    ed52a8ab <Kouhei Sutou>  Add PlasmaClientOptions
---
 c_glib/plasma-glib/client.cpp                      | 137 ++++++++++++++++++++-
 c_glib/plasma-glib/client.h                        |  21 ++++
 .../test/plasma/test-plasma-client-options.rb      |  21 ++--
 c_glib/test/plasma/test-plasma-client.rb           |   3 +-
 c_glib/test/plasma/test-plasma-created-object.rb   |   2 +-
 c_glib/test/plasma/test-plasma-referred-object.rb  |   2 +-
 ruby/red-plasma/lib/plasma/client.rb               |  13 +-
 ruby/red-plasma/test/test-plasma-client.rb         |  24 +++-
 8 files changed, 201 insertions(+), 22 deletions(-)

diff --git a/c_glib/plasma-glib/client.cpp b/c_glib/plasma-glib/client.cpp
index 9591a0a..2038ea6 100644
--- a/c_glib/plasma-glib/client.cpp
+++ b/c_glib/plasma-glib/client.cpp
@@ -39,6 +39,9 @@ G_BEGIN_DECLS
  * @title: Client related classes
  * @include: plasma-glib/plasma-glib.h
  *
+ * #GPlasmaClientOptions is a class for customizing plasma store
+ * connection.
+ *
  * #GPlasmaClientCreateOptions is a class for customizing object creation.
  *
  * #GPlasmaClient is a class for an interface with a plasma store.
@@ -46,6 +49,131 @@ G_BEGIN_DECLS
  * Since: 0.12.0
  */
 
+typedef struct GPlasmaClientCreatePrivate_ {
+  gint n_retries;
+} GPlasmaClientOptionsPrivate;
+
+enum {
+  PROP_N_RETRIES = 1
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GPlasmaClientOptions,
+                           gplasma_client_options,
+                           G_TYPE_OBJECT)
+
+#define GPLASMA_CLIENT_OPTIONS_GET_PRIVATE(object)      \
+  static_cast<GPlasmaClientOptionsPrivate *>(           \
+    gplasma_client_options_get_instance_private(        \
+      GPLASMA_CLIENT_OPTIONS(object)))
+
+static void
+gplasma_client_options_set_property(GObject *object,
+                                    guint prop_id,
+                                    const GValue *value,
+                                    GParamSpec *pspec)
+{
+  auto priv = GPLASMA_CLIENT_OPTIONS_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_N_RETRIES:
+    priv->n_retries = g_value_get_int(value);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+gplasma_client_options_get_property(GObject *object,
+                                    guint prop_id,
+                                    GValue *value,
+                                    GParamSpec *pspec)
+{
+  auto priv = GPLASMA_CLIENT_OPTIONS_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_N_RETRIES:
+    g_value_set_int(value, priv->n_retries);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+gplasma_client_options_init(GPlasmaClientOptions *object)
+{
+}
+
+static void
+gplasma_client_options_class_init(GPlasmaClientOptionsClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->set_property = gplasma_client_options_set_property;
+  gobject_class->get_property = gplasma_client_options_get_property;
+
+  GParamSpec *spec;
+  spec = g_param_spec_int("n-retries",
+                          "N retries",
+                          "The number of retries to connect plasma store. "
+                          "-1 means that the system default value is used.",
+                          -1,
+                          G_MAXINT,
+                          -1,
+                          static_cast<GParamFlags>(G_PARAM_READWRITE |
+                                                   G_PARAM_CONSTRUCT));
+  g_object_class_install_property(gobject_class, PROP_N_RETRIES, spec);
+}
+
+/**
+ * gplasma_client_options_new:
+ *
+ * Returns: A newly created #GPlasmaClientOptions.
+ *
+ * Since: 0.12.0
+ */
+GPlasmaClientOptions *
+gplasma_client_options_new(void)
+{
+  auto options = g_object_new(GPLASMA_TYPE_CLIENT_OPTIONS,
+                              NULL);
+  return GPLASMA_CLIENT_OPTIONS(options);
+}
+
+/**
+ * gplasma_client_options_set_n_retries:
+ * @options: A #GPlasmaClientOptions.
+ * @n_retries: The number of retires on connect.
+ *
+ * Since: 0.12.0
+ */
+void
+gplasma_client_options_set_n_retries(GPlasmaClientOptions *options,
+                                     gint n_retries)
+{
+  auto priv = GPLASMA_CLIENT_OPTIONS_GET_PRIVATE(options);
+  priv->n_retries = n_retries;
+}
+
+/**
+ * gplasma_client_options_get_n_retries:
+ * @options: A #GPlasmaClientOptions.
+ *
+ * Returns: The number of retries on connect.
+ *
+ * Since: 0.12.0
+ */
+gint
+gplasma_client_options_get_n_retries(GPlasmaClientOptions *options)
+{
+  auto priv = GPLASMA_CLIENT_OPTIONS_GET_PRIVATE(options);
+  return priv->n_retries;
+}
+
+
 typedef struct GPlasmaClientCreateOptionsPrivate_ {
   guint8 *metadata;
   gsize metadata_size;
@@ -182,6 +310,7 @@ gplasma_client_create_options_get_metadata(GPlasmaClientCreateOptions *options,
   return priv->metadata;
 }
 
+
 typedef struct GPlasmaClientPrivate_ {
   plasma::PlasmaClient *client;
   bool disconnected;
@@ -262,6 +391,7 @@ gplasma_client_class_init(GPlasmaClientClass *klass)
 /**
  * gplasma_client_new:
  * @store_socket_name: The name of the UNIX domain socket.
+ * @options: (nullable): The options to custom how to connect to plasma store.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
  * Returns: (nullable): A newly created #GPlasmaClient on success,
@@ -271,10 +401,15 @@ gplasma_client_class_init(GPlasmaClientClass *klass)
  */
 GPlasmaClient *
 gplasma_client_new(const gchar *store_socket_name,
+                   GPlasmaClientOptions *options,
                    GError **error)
 {
   auto plasma_client = new plasma::PlasmaClient();
-  auto status = plasma_client->Connect(store_socket_name, "");
+  int n_retries = -1;
+  if (options) {
+    n_retries = gplasma_client_options_get_n_retries(options);
+  }
+  auto status = plasma_client->Connect(store_socket_name, "", 0, n_retries);
   if (garrow_error_check(error, status, "[plasma][client][new]")) {
     return gplasma_client_new_raw(plasma_client);
   } else {
diff --git a/c_glib/plasma-glib/client.h b/c_glib/plasma-glib/client.h
index 34b0ba2..2cb983e 100644
--- a/c_glib/plasma-glib/client.h
+++ b/c_glib/plasma-glib/client.h
@@ -23,6 +23,26 @@
 
 G_BEGIN_DECLS
 
+#define GPLASMA_TYPE_CLIENT_OPTIONS (gplasma_client_options_get_type())
+G_DECLARE_DERIVABLE_TYPE(GPlasmaClientOptions,
+                         gplasma_client_options,
+                         GPLASMA,
+                         CLIENT_OPTIONS,
+                         GObject)
+
+struct _GPlasmaClientOptionsClass
+{
+  GObjectClass parent_class;
+};
+
+GPlasmaClientOptions *gplasma_client_options_new(void);
+void
+gplasma_client_options_set_n_retries(GPlasmaClientOptions *options,
+                                     gint n_retries);
+gint
+gplasma_client_options_get_n_retries(GPlasmaClientOptions *options);
+
+
 #define GPLASMA_TYPE_CLIENT_CREATE_OPTIONS      \
   (gplasma_client_create_options_get_type())
 G_DECLARE_DERIVABLE_TYPE(GPlasmaClientCreateOptions,
@@ -59,6 +79,7 @@ struct _GPlasmaClientClass
 };
 
 GPlasmaClient *gplasma_client_new(const gchar *store_socket_name,
+                                  GPlasmaClientOptions *options,
                                   GError **error);
 GPlasmaCreatedObject *
 gplasma_client_create(GPlasmaClient *client,
diff --git a/ruby/red-plasma/test/test-plasma-client.rb b/c_glib/test/plasma/test-plasma-client-options.rb
similarity index 72%
copy from ruby/red-plasma/test/test-plasma-client.rb
copy to c_glib/test/plasma/test-plasma-client-options.rb
index e7f8dbd..abe6fd3 100644
--- a/ruby/red-plasma/test/test-plasma-client.rb
+++ b/c_glib/test/plasma/test-plasma-client-options.rb
@@ -15,20 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class TestPlasmaClient < Test::Unit::TestCase
-  def setup
-    @store = nil
-    @store = Helper::PlasmaStore.new
-    @store.start
-  end
+class TestPlasmaClientOptions < Test::Unit::TestCase
+  include Helper::Omittable
 
-  def teardown
-    @store.stop if @store
+  def setup
+    omit("Plasma is required") unless defined?(::Plasma)
+    @options = Plasma::ClientOptions.new
   end
 
-  def test_new
-    assert_nothing_raised do
-      Plasma::Client.new(Pathname(@store.socket_path))
-    end
+  test("n_retries") do
+    assert_equal(-1, @options.n_retries)
+    @options.n_retries = 10
+    assert_equal(10, @options.n_retries)
   end
 end
diff --git a/c_glib/test/plasma/test-plasma-client.rb b/c_glib/test/plasma/test-plasma-client.rb
index 6caf09f..a57d1fc 100644
--- a/c_glib/test/plasma/test-plasma-client.rb
+++ b/c_glib/test/plasma/test-plasma-client.rb
@@ -23,7 +23,8 @@ class TestPlasmaClient < Test::Unit::TestCase
     omit("Plasma is required") unless defined?(::Plasma)
     @store = Helper::PlasmaStore.new
     @store.start
-    @client = Plasma::Client.new(@store.socket_path)
+    @options = Plasma::ClientOptions.new
+    @client = Plasma::Client.new(@store.socket_path, @options)
     @id = Plasma::ObjectID.new("Hello")
     @data = "World"
     @options = Plasma::ClientCreateOptions.new
diff --git a/c_glib/test/plasma/test-plasma-created-object.rb b/c_glib/test/plasma/test-plasma-created-object.rb
index 54d6774..9025ff4 100644
--- a/c_glib/test/plasma/test-plasma-created-object.rb
+++ b/c_glib/test/plasma/test-plasma-created-object.rb
@@ -21,7 +21,7 @@ class TestPlasmaCreatedObject < Test::Unit::TestCase
     omit("Plasma is required") unless defined?(::Plasma)
     @store = Helper::PlasmaStore.new
     @store.start
-    @client = Plasma::Client.new(@store.socket_path)
+    @client = Plasma::Client.new(@store.socket_path, nil)
 
     @id = Plasma::ObjectID.new("Hello")
     @data = "World"
diff --git a/c_glib/test/plasma/test-plasma-referred-object.rb b/c_glib/test/plasma/test-plasma-referred-object.rb
index f55c0b1..a74641e 100644
--- a/c_glib/test/plasma/test-plasma-referred-object.rb
+++ b/c_glib/test/plasma/test-plasma-referred-object.rb
@@ -21,7 +21,7 @@ class TestPlasmaReferredObject < Test::Unit::TestCase
     omit("Plasma is required") unless defined?(::Plasma)
     @store = Helper::PlasmaStore.new
     @store.start
-    @client = Plasma::Client.new(@store.socket_path)
+    @client = Plasma::Client.new(@store.socket_path, nil)
 
     @id = Plasma::ObjectID.new("Hello")
     @data = "World"
diff --git a/ruby/red-plasma/lib/plasma/client.rb b/ruby/red-plasma/lib/plasma/client.rb
index 464ef8c..d32ded6 100644
--- a/ruby/red-plasma/lib/plasma/client.rb
+++ b/ruby/red-plasma/lib/plasma/client.rb
@@ -18,9 +18,18 @@
 module Plasma
   class Client
     alias_method :initialize_raw, :initialize
-    def initialize(socket_path)
+    private :initialize_raw
+    def initialize(socket_path, options=nil)
       socket_path = socket_path.to_path if socket_path.respond_to?(:to_path)
-      initialize_raw(socket_path)
+      if options
+        options_raw = options
+        options = ClientOptions.new
+        options_raw.each do |key, value|
+          setter = "#{key}="
+          options.__send__(setter, value) if options.respond_to?(setter)
+        end
+      end
+      initialize_raw(socket_path, options)
     end
   end
 end
diff --git a/ruby/red-plasma/test/test-plasma-client.rb b/ruby/red-plasma/test/test-plasma-client.rb
index e7f8dbd..de76fb9 100644
--- a/ruby/red-plasma/test/test-plasma-client.rb
+++ b/ruby/red-plasma/test/test-plasma-client.rb
@@ -20,15 +20,31 @@ class TestPlasmaClient < Test::Unit::TestCase
     @store = nil
     @store = Helper::PlasmaStore.new
     @store.start
+    @id = Plasma::ObjectID.new("Hello")
+    @data = "World"
   end
 
   def teardown
     @store.stop if @store
   end
 
-  def test_new
-    assert_nothing_raised do
-      Plasma::Client.new(Pathname(@store.socket_path))
-    end
+  def test_new_pathname
+    client = Plasma::Client.new(Pathname(@store.socket_path))
+    object = client.create(@id, @data.bytesize, nil)
+    object.data.set_data(0, @data)
+    object.seal
+
+    object = client.refer_object(@id, -1)
+    assert_equal(@data, object.data.data.to_s)
+  end
+
+  def test_new_options
+    client = Plasma::Client.new(@store.socket_path, n_retries: 1)
+    object = client.create(@id, @data.bytesize, nil)
+    object.data.set_data(0, @data)
+    object.seal
+
+    object = client.refer_object(@id, -1)
+    assert_equal(@data, object.data.data.to_s)
   end
 end