Go implementation of FrostFS SDK
Find a file
Airat Arifullin d342c0bc16
All checks were successful
DCO / DCO (pull_request) Successful in 40s
Tests and linters / Tests (pull_request) Successful in 53s
Tests and linters / Lint (pull_request) Successful in 1m21s
[#268] client: Make PayloadPatch correctly receive empty patch payload
* Make the method `PatchPayload` send a patch with empty
  payload patch if range's length is non-zero and if it's the
  first call.
* Empty payload patches just cut original object payload. So, these
  patches are also valid.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-09-12 15:12:52 +03:00
.forgejo/workflows [#1316] go.mod: Bump go version to 1.22 2024-08-21 16:42:58 +03:00
.github [#98] Add forgejo workflows 2023-06-28 12:13:02 +00:00
accounting Rename package name 2023-03-07 15:47:21 +03:00
ape [#225] apemanager: Move apemanager to ape package 2024-05-31 12:14:42 +00:00
bearer [#225] bearer: Introduce APEOverride field for the token 2024-05-31 12:14:42 +00:00
checksum [#170] checksum: Use constant mapping for checksum types 2023-09-28 17:20:24 +03:00
client [#268] client: Make PayloadPatch correctly receive empty patch payload 2024-09-12 15:12:52 +03:00
container [#265] go.mod: Use range over int 2024-09-04 12:37:46 +03:00
crypto [#161] *: Do not use math/rand.Read() 2023-09-08 17:17:02 +03:00
doc [#203] Add pool docs 2024-08-30 08:24:31 +03:00
eacl [#265] go.mod: Use range over int 2024-09-04 12:37:46 +03:00
netmap [#217] netmap: Return node netmap state directly 2024-09-09 08:51:51 +00:00
ns [#161] *: Do not use math/rand.Read() 2023-09-08 17:17:02 +03:00
object [#265] go.mod: Use range over int 2024-09-04 12:37:46 +03:00
pool [#260] *: Fix linter warnings 2024-09-09 08:55:32 +00:00
session [#249] session: Support patch verb 2024-08-08 18:26:40 +03:00
user [#236] *: Replace slice.Copy() with bytes.Clone() 2024-07-12 15:43:07 +03:00
version Rename package name 2023-03-07 15:47:21 +03:00
.gitattributes [#3] policy: use ANTLRv4 parser generator 2021-06-15 11:42:14 +03:00
.gitignore [#183] forgejo: Make linter great again 2023-10-23 18:13:40 +03:00
.golangci.yml [#260] .golangci.yml: Add protogetter linter 2024-09-09 08:55:32 +00:00
.pre-commit-config.yaml [#209] pre-commit: Add unit-test hook 2024-03-14 13:35:48 +03:00
Dockerfile [#1316] go.mod: Bump go version to 1.22 2024-08-21 16:42:58 +03:00
go.mod [#263] go.mod: Update api-go 2024-09-03 12:36:28 +03:00
go.sum [#263] go.mod: Update api-go 2024-09-03 12:36:28 +03:00
LICENSE Initial commit 2021-02-25 11:35:04 +03:00
Makefile [#260] Makefile: Add pre-commit targets 2024-09-09 08:55:32 +00:00
README.md [#131] client: keep backwards-compatibility, update README.md, fix chore 2023-10-26 14:35:49 +00:00
syncTree.sh [#239] pool/tree: Update tree service client 2024-07-17 14:32:04 +03:00

frostfs-sdk-go

Go implementation of FrostFS SDK. It contains high-level version-independent wrappers for structures from frostfs-api-go as well as helper functions for simplifying node/dApp implementations.

Repository structure

accounting

Contains fixed-point Decimal type for performing balance calculations.

eacl

Contains Extended ACL types for fine-grained access control. There is also a reference implementation of checking algorithm which is used in FrostFS node.

checksum

Contains Checksum type encapsulating checksum as well as it's kind. Currently Sha256 and Tillich-Zemor hashsum are in use.

owner

owner.ID type represents single account interacting with FrostFS. In v2 version of protocol it is just raw bytes behing base58-encoded address in Neo blockchain. Note that for historical reasons it contains version prefix and checksum in addition to script-hash.

token

Contains Bearer token type with several FrostFS-specific methods.

ns

In FrostFS there are 2 types of name resolution: DNS and NNS. NNS stands for Neo Name Service is just a contract deployed on a Neo blockchain. Basically, NNS is just a DNS-on-chain which can be used for resolving container nice-names as well as any other name in dApps. See our CoreDNS plugin for the example of how NNS can be integrated in DNS.

session

To help lightweight clients interact with FrostFS without sacrificing trust, FrostFS has a concept of session token. It is signed by client and allows any node with which a session is established to perform certain actions on behalf of the user.

client

Contains client for working with FrostFS.

var prmInit client.PrmInit
prmInit.SetDefaultPrivateKey(key) // private key for request signing

var c client.Client
c.Init(prmInit)

var prmDial client.PrmDial
prmDial.SetServerURI("grpcs://localhost:40005") // endpoint address

err := c.Dial(prmDial)
if err != nil {
    return
}

ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
defer cancel()

var prm client.PrmBalanceGet
prm.SetAccount(acc)

res, err := c.BalanceGet(ctx, prm)
if err != nil {
    return
}

fmt.Printf("Balance for %s: %v\n", acc, res.Amount())

Response status

In FrostFS every operation can fail on multiple levels, so a single error doesn't suffice, e.g. consider a case when object was put on 4 out of 5 replicas. Thus, all request execution details are contained in Status returned from every RPC call. dApp can inspect them if needed and perform any desired action. In the case above we may want to report these details to the user as well as retry an operation, possibly with different parameters. Status wire-format is extendable and each node can report any set of details it wants. The set of reserved status codes can be found in FrostFS API.

policy

Contains helpers allowing conversion of placing policy from/to JSON representation and SQL-like human-readable language.

p, _ := policy.Parse(`
    REP 2
    SELECT 6 FROM F
    FILTER StorageType EQ SSD AS F`)

// Convert parsed policy back to human-readable text and print.
println(strings.Join(policy.Encode(p), "\n"))

netmap

Contains CRUSH-like implementation of container node selection algorithm. Relevant details are described in this paper http://ceur-ws.org/Vol-2344/short10.pdf . Note that it can be outdated in some details.

netmap/json_tests subfolder contains language-agnostic tests for selection algorithm.

import (
    "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
    "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
)

func placementNodes(addr *object.Address, p *netmap.PlacementPolicy, frostfsNodes []netmap.NodeInfo) {
    // Convert list of nodes in FrostFS API format to the intermediate representation.
    nodes := netmap.NodesFromInfo(nodes)

    // Create new netmap (errors are skipped for the sake of clarity).
    nm, _ := NewNetmap(nodes)

    // Calculate nodes of container.
    cn, _ := nm.GetContainerNodes(p, addr.ContainerID().ToV2().GetValue())

    // Return list of nodes for each replica to place object on in the order of priority.
    return nm.GetPlacementVectors(cn, addr.ObjectID().ToV2().GetValue())
}

pool

Simple pool for managing connections to FrostFS nodes.

acl, checksum, version, signature

Contain simple API wrappers.

logger

Wrapper over zap.Logger which is used across FrostFS codebase.

util

Utilities for working with signature-related code.