Skip to content

Commit

Permalink
Merge pull request #286 from basho/fixes/lrb/time-correction-gh-284
Browse files Browse the repository at this point in the history
READY: Improve erlang:now deprecation define regex
  • Loading branch information
lukebakken committed May 24, 2016
2 parents eed7071 + 23e8d5b commit 96f2b74
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.rebar/
.eunit/*
deps/*
priv/*
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
language: erlang
before_script:
- export RIAK_TEST_NODE_1=`egrep '^\-s?name' /etc/riak/vm.args | awk '{print $2}'`
- export RIAK_TEST_COOKIE=`egrep '^-setcookie' /etc/riak/vm.args | awk '{print $2}'`
notifications:
webhooks: http://basho-engbot.herokuapp.com/travis?key=8f07584549e458d4c83728f3397ecbd4368e60a8
email: eng@basho.com
otp_release:
- 18.1
- 18.3
- 17.5
- R16B03
- R16B02
119 changes: 47 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<p align="right">
<img src="http://wiki.basho.com/images/riaklogo.png">
</p>
# Riak Protocol Buffers Client Introduction
# Riak Erlang Client

[![Build Status](https://secure.travis-ci.org/basho/riak-erlang-client.png?branch=master)](http://travis-ci.org/basho/riak-erlang-client)
This document assumes that you have already started your Riak cluster. For instructions on that prerequisite, refer to the [setup][kv_setup] guide in the [Basho Docs][basho_docs]. You can also view the Riak Erlang Client EDocs [here][erlang_client_edocs].

This document assumes that you have already started your Riak cluster.
For instructions on that prerequisite, refer to the
[Quick Start](http://docs.basho.com/riak/latest/quickstart/) guide
in the [Basho Docs](https://docs.basho.com). You can also view the Riak Erlang Client EDocs [here](http://basho.github.com/riak-erlang-client/).
Build Status
============

* Master: [![Build Status](https://travis-ci.org/basho/riak-erlang-client.svg?branch=master)](https://travis-ci.org/basho/riak-erlang-client)

Dependencies
=========
============

To build the riak-erlang-client you will need Erlang OTP R15B01 or later, and Git.

Expand All @@ -24,15 +21,15 @@ On a Debian based system (Debian, Ubuntu, ...) you will need to make sure that c


Installing
=========
==========

$ git clone git://github.com/basho/riak-erlang-client.git
$ cd riak-erlang-client
$ make


Connecting
=======
==========

To talk to riak, all you need is an Erlang node with the riak-erlang-client library (riakc) in its code path.

Expand All @@ -57,7 +54,7 @@ Verify connectivity with the server using `ping/1`.


Storing New Data
=========
================

Each bit of data in Riak is stored in a "bucket" at a "key" that is unique to that bucket. The bucket is intended as an organizational aid, for example to help segregate data by type, but Riak doesn't care what values it stores, so choose whatever scheme suits you. Buckets, keys and values are all binaries.

Expand Down Expand Up @@ -98,7 +95,7 @@ The object is now stored in Riak. `put/2` uses default parameters for storing th
</tr>
</table>

See [Default Bucket Properties](http://docs.basho.com/riak/latest/ops/advanced/configs/configuration-files/#Default-Bucket-Properties) for more details.
See [Default Bucket Properties][kv_configuring_reference_bucket_properties] for more details.


6> AnotherObject = riakc_obj:new(<<"my bucket">>, <<"my key">>, <<"my binary data">>).
Expand All @@ -117,12 +114,10 @@ See [Default Bucket Properties](http://docs.basho.com/riak/latest/ops/advanced/c

Would make sure at least two nodes responded successfully to the put and at least one node has durably stored the value and an updated object is returned.

See [riak/doc/architecture.txt](https://github.com/basho/riak/blob/master/doc/architecture.txt) for more information about W and DW
values.

See [this page][kv_learn_glossary_quorum] for more information about W and DW values.

Fetching Data
==================
=============

At some point you'll want that data back. Using the same bucket and key you used before:

Expand Down Expand Up @@ -150,14 +145,10 @@ Like `put/3`, there is a `get/4` function that takes options.
</tr>
</table>

If the data was originally stored using the distributed erlang client (riak_client), the server
will automatically term_to_binary/1 the value before sending it, with the content
type set to application/x-erlang-binary (replacing any user-set value). The application is
responsible for calling binary_to_term to access the content and calling term_to_binary
when modifying it.
If the data was originally stored using the distributed erlang client (riak_client), the server will automatically term_to_binary/1 the value before sending it, with the content type set to application/x-erlang-binary (replacing any user-set value). The application is responsible for calling binary_to_term to access the content and calling term_to_binary when modifying it.

Modifying Data
==================
==============

Say you had the "grocery list" from the examples above, reminding you to get `<<"eggs & bacon">>`, and you want to add `<<"milk">>` to it. The easiest way is:

Expand All @@ -181,7 +172,7 @@ Say you had the "grocery list" from the examples above, reminding you to get `<<
That is, fetch the object from Riak, modify its value with `riakc_obj:update_value/2`, then store the modified object back in Riak. You can get your updated object to convince yourself that your list is updated:

Deleting Data
==================
=============

Throwing away data is quick and simple: just use the `delete/3` function.

Expand All @@ -202,7 +193,7 @@ As with get and put, delete can also take options
Issuing a delete for an object that does not exist returns just returns ok.

Encoding
==================
========

The initial release of the erlang protocol buffers client treats all values as binaries. The caller needs to make sure data is serialized and deserialized correctly. The content type stored along with the object may be used to store the encoding. For example

Expand All @@ -224,7 +215,7 @@ The initial release of the erlang protocol buffers client treats all values as b
<<"application/x-erlang-term">>).

Siblings
==================
========

If a bucket is configured to allow conflicts (allow_mult=true) then the result object may contain more than one result. The number of values can be returned with

Expand All @@ -248,7 +239,7 @@ It is also possible to get a list of tuples representing all the siblings throug
Once the correct combination of metadata and value has been determined, the record can be updated with these using the `riakc_obj:update_value` and `riakc_obj:update_metadata` functions. If the resulting content type needs to be updated, the `riakc_obj:update_content_type` can be used.

Listing Keys
=============
============

Most uses of key-value stores are structured in such a way that requests know which keys they want in a bucket. Sometimes, though, it's necessary to find out what keys are available (when debugging, for example). For that, there is list_keys:

Expand All @@ -269,7 +260,7 @@ Note that keylist updates are asynchronous to the object storage primitives, and
See [`riakc_pb_socket:wait_for_listkeys`](https://github.com/basho/riak-erlang-client/blob/master/src/riakc_pb_socket.erl#L1087) for an example of receiving.

Bucket Properties
==================
=================

Bucket properties can be retrieved and modified using `get_bucket/2` and `set_bucket/3`. The bucket properties are represented as a proplist. Only a subset of the properties can be retrieved and set using the protocol buffers interface - currently only n_val and allow_mult.

Expand All @@ -288,7 +279,7 @@ Here's an example of getting/setting properties


User Metadata
==================
=============

User metadata are stored in the object metadata dictionary, and can be manipulated by using the `get_user_metadata_entry/2`, `get_user_metadata_entries/1`, `clear_user_metadata_entries/1`, `delete_user_metadata_entry/2` and `set_user_metadata_entry/2` functions.

Expand Down Expand Up @@ -348,7 +339,7 @@ The following example illustrates setting and getting metadata.


Secondary Indexes
==================
=================

Secondary indexes are set through the object metadata dictionary, and can be manipulated by using the `get_secondary_index/2`, `get_secondary_indexes/1`, `clear_secondary_indexes/1`, `delete_secondary_index/2`, `set_secondary_index/2` and `add_secondary_index/2` functions. These functions act upon the dictionary returned by the `get_metadata/1`, `get_metadatas/1` and `get_update_metadata/1` functions.

Expand Down Expand Up @@ -407,7 +398,7 @@ The following example illustrates how to perform exact match as well as range qu
Riak Data Types
===============

[Riak Data Types](http://docs.basho.com/riak/2.0.0pre20/dev/using/data-types/) can only be used in buckets of a [bucket type](http://docs.basho.com/riak/2.0.0pre20/dev/advanced/bucket-types/) in which the `datatype` bucket property is set to either `counter`, `set`, or `map`.
[Riak Data Types][kv_developing_data_types] can only be used in buckets of a [bucket type][kv_developing_data_types_setting_up] in which the `datatype` bucket property is set to either `counter`, `set`, or `map`.

All Data Types in the Erlang client can be created and modified at will prior to being stored. Basic CRUD operations are performed by functions in `riakc_pb_socket` specific to Data Types, e.g. `fetch_type/3,4` instead of `get/3,4,5` for normal objects, `update_type/4,5` instead of `put/2,3,4`, etc.

Expand Down Expand Up @@ -461,10 +452,7 @@ Once client-side updates are completed, updating sets in Riak works just like up

Now, a set with the elements `bar` and `baz` will be stored in `/types/set_bucket/buckets/all_my_sets/keys/odds_and_ends`.

The functions `size/1`, `is_element/2`, and `fold/3` will work only on
values stored in and retrieved from Riak. Any local modifications,
including initial values when an object is created, will not be
considered.
The functions `size/1`, `is_element/2`, and `fold/3` will work only on values stored in and retrieved from Riak. Any local modifications, including initial values when an object is created, will not be considered.

riakc_set:is_element(<<"bar">>, Set4).
%% false
Expand All @@ -483,7 +471,7 @@ Updating maps involves both specifying the map field that you wish to update (by
fun(R) -> riakc_register:set(<<"foo">>, R) end,
Map).

For more detailed instructions on maps, see the [Using Data Types](http://docs.basho.com/riak/latest/dev/using/data-types/#Maps) documentation.
For more detailed instructions on maps, see the [documentation][kv_developing_data_types_maps].

Links
=====
Expand Down Expand Up @@ -617,27 +605,11 @@ Create a qfun that returns the size of the record and feed this into the existin
Security
========

If you are using Riak's new [security
feature](http://docs.basho.com/riak/latest/ops/running/authz/)
introduced in version 2.0, you will need to configure your Riak Erlang
client to use SSL when connecting to Riak. The required setup depends on
the [security
source](http://docs.basho.com/riak/latest/ops/running/security-sources/)
that you choose. A general primer on Riak client security can be found
in our [official
docs](http://docs.basho.com/riak/latest/dev/advanced/client-security/).

Regardless of which authentication source you use, your client will need
to have access to a certificate authority (CA) shared by your Riak
server. You will also need to provide a username that corresponds to the
username for the user or role that you have [created in
Riak](http://docs.basho.com/riak/latest/ops/running/authz/#User-Management).

Let's say that your CA is stored in the `/ssl_dir` directory and bears
the name `cacertfile.pem` and that you need provide a username of
`riakuser` and a password of `rosebud`. You can input that information
as a list of tuples when you create your process identifier (PID) for
further connections to Riak:
If you are using [Riak Security][kv_using_security_basics], you will need to configure your Riak Erlang client to use SSL when connecting to Riak. The required setup depends on the [security source][kv_using_security_managing_sources] that you choose. A general primer on Riak client security can be found in our [official docs][kv_developing_usage_security].

Regardless of which authentication source you use, your client will need to have access to a certificate authority (CA) shared by your Riak server. You will also need to provide a username that corresponds to the username for the user or role that you have [created in Riak][kv_using_security_basics_user_mgmt].

Let's say that your CA is stored in the `/ssl_dir` directory and bears the name `cacertfile.pem` and that you need provide a username of `riakuser` and a password of `rosebud`. You can input that information as a list of tuples when you create your process identifier (PID) for further connections to Riak:

```erlang
CertDir = "/ssl_dir",
Expand All @@ -648,19 +620,9 @@ SecurityOptions = [
{ok, Pid} = riakc_pb_socket:start("127.0.0.1", 8087, SecurityOptions).
```

This setup will suffice for
[password-](http://docs.basho.com/riak/latest/ops/running/security-sources/#Password-based-Authentication),
[PAM-](http://docs.basho.com/riak/latest/ops/running/security-sources/#PAM-based-Authentication)
and
[trust](http://docs.basho.com/riak/latest/ops/running/security-sources/#Trust-based-Authentication)-based
authentication.
This setup will suffice for [password, PAM and trust][kv_using_security_basics] based authentication.

If you are using [certificate-based
authentication](http://docs.basho.com/riak/latest/dev/advanced/client-security/erlang/#Certificate-based-Authentication),
you will also need to specify a cert and keyfile. The example below uses
the same connection information from the sample above but also points to
a cert called `cert.pem` and a keyfile called `key.pem` (both stored in
the same `/ssl_dir` directory as the CA):
If you are using [certificate-based authentication][kv_using_security_basics_certs], you will also need to specify a cert and keyfile. The example below uses the same connection information from the sample above but also points to a cert called `cert.pem` and a keyfile called `key.pem` (both stored in the same `/ssl_dir` directory as the CA):

```erlang
CertDir = "/ssl_dir",
Expand All @@ -673,10 +635,23 @@ SecurityOptions = [
{ok, Pid} = riakc_pb_socket:start("127.0.0.1", 8087, SecurityOptions).
```

More detailed information can be found in our [official
documentation](http://docs.basho.com/riak/latest/dev/advanced/client-security/erlang/).
More detailed information can be found in our [official documentation][kv_using_security_basics].

Troubleshooting
==================

If `start/2` or `start_link/2` return `{error,econnrefused}` the client could not connect to the server - make sure the protocol buffers interface is enabled on the server and the address/port is correct.

[basho_docs]: http://docs.basho.com/
[kv_setup]: http://docs.basho.com/riak/kv/latest/setup/
[erlang_client_edocs]: http://basho.github.com/riak-erlang-client/
[kv_developing_data_types]: http://docs.basho.com/riak/kv/latest/developing/data-types/
[kv_developing_data_types_setting_up]: http://docs.basho.com/riak/kv/latest/developing/data-types/#setting-up-buckets-to-use-riak-data-types
[kv_developing_data_types_maps]: http://docs.basho.com/riak/kv/latest/developing/data-types/#maps
[kv_configuring_reference_bucket_properties]: https://docs.basho.com/riak/kv/latest/configuring/reference/#default-bucket-properties
[kv_learn_glossary_quorum]: http://docs.basho.com/riak/kv/latest/learn/glossary/#quorum
[kv_using_security_managing_sources]: http://docs.basho.com/riak/kv/latest/using/security/managing-sources/
[kv_using_security_basics]: https://docs.basho.com/riak/kv/latest/using/security/basics/
[kv_developing_usage_security]: https://docs.basho.com/riak/kv/latest/developing/usage/security/
[kv_using_security_basics_user_mgmt]: https://docs.basho.com/riak/kv/latest/using/security/basics/#user-management
[kv_using_security_basics_certs]: https://docs.basho.com/riak/kv/latest/using/security/basics/#certificate-configuration
Binary file modified rebar
Binary file not shown.
5 changes: 3 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{require_otp_vsn, "R15|R16|17|18"}.
{require_otp_vsn, "R15|R16|17|18|19"}.

{cover_enabled, true}.

Expand All @@ -8,8 +8,9 @@
debug_info,
warnings_as_errors,
{platform_define, "^[0-9]+", namespaced_types},
{platform_define, "^18", deprecated_now}
{platform_define, "(?=^[0-9]+)(?!^17)", deprecated_now}
]}.

{deps, [
{riak_pb, "2.1.0.7", {git, "git://github.com/basho/riak_pb", {tag, "2.1.0.7"}}}
]}.
Expand Down

0 comments on commit 96f2b74

Please sign in to comment.