Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using fully qualified module path #116

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7314a40
using fully qualified module path
Ahmadkashif May 21, 2023
3c7ae7f
Adding comments for documentation for clientImpl.go
Ahmadkashif May 21, 2023
34b2e12
Adding comments for documentation for config.go
Ahmadkashif May 21, 2023
873ce04
Adding comments for documentation for error.go
Ahmadkashif May 21, 2023
9325722
Adding comments for documentation for option.go
Ahmadkashif May 21, 2023
77c6893
Updating imports for clustermgr, clusterctl, ctx, proc, processor, re…
Ahmadkashif May 21, 2023
10eb923
Updating imports for all golang files
Ahmadkashif May 21, 2023
efad306
Bump actions/setup-go from 4.0.0 to 4.0.1
dependabot[bot] May 22, 2023
bd25f8c
Merge pull request #126 from paypal/dependabot/github_actions/actions…
NeetishPathak May 22, 2023
a109fb4
Fixing Build error
Ahmadkashif May 24, 2023
106bb37
Bump spring-boot-autoconfigure
dependabot[bot] Jun 2, 2023
dfb0ed0
Merge pull request #138 from paypal/dependabot/maven/client/Java/exam…
NeetishPathak Jun 13, 2023
2a1aab1
Docker build changes. 1. Adding error return in shell script. 2. Chan…
NeetishPathak Jun 13, 2023
4dbf886
Docker build supported platforms
NeetishPathak Jun 13, 2023
d306aa5
Merge pull request #143 from NeetishPathak/dev
NeetishPathak Jun 13, 2023
abd1988
support fixed key range in junoload
yapingshi Jul 7, 2023
9b8470d
Fix: Dependabot alerts
nit-tripathi Aug 10, 2023
77c0c8b
Merge pull request #147 from nit-tripathi/dev
NeetishPathak Aug 10, 2023
3f55f7e
moved ruby client to opensource
Aug 11, 2023
ca68aa1
Merge pull request #148 from VaibhavA19/dev
jostanislas Aug 11, 2023
960cf41
Merge branch 'dev' into Issue_113_UseQualiFiedPathForGoMod
Ahmadkashif Aug 15, 2023
da92a37
add swaphost and host_expansion instruction document
verapaypal Dec 4, 2023
7f288b4
Comment out macos-latest docker build, facing docker issue on image h…
NeetishPathak Dec 4, 2023
c688ed9
Merge pull request #166 from NeetishPathak/dev
NeetishPathak Dec 5, 2023
6f0f334
add more info into host_expansion.md
Dec 5, 2023
566714b
update deploy.sh to copy swaphost etc. script, update help message fo…
verapaypal Dec 14, 2023
4aa682e
Added otel collector and prometheus configs
Dec 16, 2023
b06d739
Adding prometheus , otel mornitoring setup and docs (#168)
NeetishPathak Dec 18, 2023
5dde26e
Merge branch 'dev' of /~https://github.com/paypal/junodb into dev
Dec 18, 2023
8a2b6e6
Updated OTEL metrics
Dec 21, 2023
74081b4
Merge pull request #169 from jostanislas/dev
NeetishPathak Dec 21, 2023
72a9a25
Fixed build failure (#171)
jostanislas Dec 22, 2023
16098b1
Fixed etcd join.
art2ip Jan 9, 2024
c7a62b4
Merge pull request #172 from art2ip/juno_24_0108
art2ip Jan 9, 2024
1b31d80
Merge branch 'dev' into Issue_113_UseQualiFiedPathForGoMod
NeetishPathak May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module juno
module github.com/paypal/junodb

go 1.18

Expand Down
21 changes: 21 additions & 0 deletions pkg/client/clientimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// limitations under the License.
//

// Package client provides interfaces and implementations for communicating with a Juno server.
package client

import (
Expand All @@ -31,13 +32,15 @@ import (
"juno/pkg/proto"
)

// clientImplT is the default implementation of the IClient interface.
type clientImplT struct {
config Config
appName string
namespace string
processor *cli.Processor
}

// newProcessorWithConfig initializes a new Processor with the given configuration.
func newProcessorWithConfig(conf *Config) *cli.Processor {
if conf == nil {
return nil
Expand All @@ -51,6 +54,7 @@ func newProcessorWithConfig(conf *Config) *cli.Processor {
return c
}

// New initializes a new IClient with the given configuration. Returns an error if configuration validation fails.
func New(conf Config) (IClient, error) {
if err := conf.validate(); err != nil {
return nil, err
Expand All @@ -68,6 +72,7 @@ func New(conf Config) (IClient, error) {
return client, nil
}

// NewClient initializes a new IClient with the provided server address, namespace and app name.
func NewClient(server string, ns string, app string) (IClient, error) {
c := &clientImplT{
config: Config{
Expand Down Expand Up @@ -99,13 +104,16 @@ func NewClient(server string, ns string, app string) (IClient, error) {
}

///TODO to revisit

// Close closes the client and cleans up resources.
func (c *clientImplT) Close() {
if c.processor != nil {
c.processor.Close()
c.processor = nil
}
}

// getOptions collects all provided options into an optionData object.
func (c *clientImplT) getOptions(opts ...IOption) *optionData {
data := &optionData{}
for _, op := range opts {
Expand All @@ -114,12 +122,14 @@ func (c *clientImplT) getOptions(opts ...IOption) *optionData {
return data
}

// newContext creates a new context from the provided operational message.
func newContext(resp *proto.OperationalMessage) IContext {
recInfo := &cli.RecordInfo{}
recInfo.SetFromOpMsg(resp)
return recInfo
}

// Create sends a Create operation request to the server.
func (c *clientImplT) Create(key []byte, value []byte, opts ...IOption) (context IContext, err error) {
glog.Verbosef("Create ")
var resp *proto.OperationalMessage
Expand All @@ -138,6 +148,7 @@ func (c *clientImplT) Create(key []byte, value []byte, opts ...IOption) (context
return
}

// Get sends a Get operation request to the server.
func (c *clientImplT) Get(key []byte, opts ...IOption) (value []byte, context IContext, err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -161,6 +172,7 @@ func (c *clientImplT) Get(key []byte, opts ...IOption) (value []byte, context IC
return
}

// Update sends an Update operation request to the server.
func (c *clientImplT) Update(key []byte, value []byte, opts ...IOption) (context IContext, err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -183,6 +195,7 @@ func (c *clientImplT) Update(key []byte, value []byte, opts ...IOption) (context
return
}

// Set sends a Set operation request to the server.
func (c *clientImplT) Set(key []byte, value []byte, opts ...IOption) (context IContext, err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -200,6 +213,7 @@ func (c *clientImplT) Set(key []byte, value []byte, opts ...IOption) (context IC
return
}

// Destroy sends a Destroy operation request to the server.
func (c *clientImplT) Destroy(key []byte, opts ...IOption) (err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -215,6 +229,7 @@ func (c *clientImplT) Destroy(key []byte, opts ...IOption) (err error) {
return
}

// UDFGet sends a UDFGet operation request to the server.
func (c *clientImplT) UDFGet(key []byte, fname []byte, params []byte, opts ...IOption) (value []byte, context IContext, err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -239,6 +254,7 @@ func (c *clientImplT) UDFGet(key []byte, fname []byte, params []byte, opts ...IO
return
}

// UDFSet sends a UDFSet operation request to the server.
func (c *clientImplT) UDFSet(key []byte, fname []byte, params []byte, opts ...IOption) (context IContext, err error) {
var resp *proto.OperationalMessage
options := newOptionData(opts...)
Expand All @@ -258,10 +274,13 @@ func (c *clientImplT) UDFSet(key []byte, fname []byte, params []byte, opts ...IO
}

///TODO temporary

// Batch sends a batch of operation requests to the server.
func (c *clientImplT) Batch(requests []*proto.OperationalMessage) (responses []*proto.OperationalMessage, err error) {
return c.processor.ProcessBatchRequests(requests)
}

// NewRequest creates a new OperationalMessage with the provided parameters.
func (c *clientImplT) NewRequest(op proto.OpCode, key []byte, value []byte, ttl uint32) (request *proto.OperationalMessage) {
///TODO: validate op
request = &proto.OperationalMessage{}
Expand All @@ -272,6 +291,7 @@ func (c *clientImplT) NewRequest(op proto.OpCode, key []byte, value []byte, ttl
return
}

// NewUDFRequest creates a new UDF OperationalMessage with the provided parameters.
func (c *clientImplT) NewUDFRequest(op proto.OpCode, key []byte, fname []byte, params []byte, ttl uint32) (request *proto.OperationalMessage) {
///TODO: validate op
request = &proto.OperationalMessage{}
Expand All @@ -284,6 +304,7 @@ func (c *clientImplT) NewUDFRequest(op proto.OpCode, key []byte, fname []byte, p
return
}

// checkResponse validates the response from the server against the original request.
func checkResponse(request *proto.OperationalMessage, response *proto.OperationalMessage, recInfo *cli.RecordInfo) (err error) {
opCode := request.GetOpCode()
if opCode != response.GetOpCode() {
Expand Down
59 changes: 34 additions & 25 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// Copyright 2023 PayPal Inc.
//
// Copyright 2023 PayPal Inc.
//
// 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
// 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.
//
// 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.

// Package client handles the configuration for a Juno client.
package client

import (
Expand All @@ -27,21 +26,24 @@ import (
"juno/pkg/util"
)

// Duration is a type alias for util.Duration.
type Duration = util.Duration

// Config holds the configuration values for the Juno client.
type Config struct {
Server io.ServiceEndpoint
Appname string
Namespace string
RetryCount int
DefaultTimeToLive int
ConnectTimeout Duration
ReadTimeout Duration
WriteTimeout Duration
RequestTimeout Duration
ConnRecycleTimeout Duration
Server io.ServiceEndpoint // Server defines the ServiceEndpoint of the Juno server.
Appname string // Appname is the name of the application.
Namespace string // Namespace is the namespace of the application.
RetryCount int // RetryCount is the maximum number of retries.
DefaultTimeToLive int // DefaultTimeToLive is the default TTL (time to live) for requests.
ConnectTimeout Duration // ConnectTimeout is the timeout for establishing connections.
ReadTimeout Duration // ReadTimeout is the timeout for read operations.
WriteTimeout Duration // WriteTimeout is the timeout for write operations.
RequestTimeout Duration // RequestTimeout is the timeout for each request.
ConnRecycleTimeout Duration // ConnRecycleTimeout is the timeout for connection recycling.
}

// defaultConfig defines the default configuration values.
var defaultConfig = Config{
RetryCount: 1,
DefaultTimeToLive: 1800,
Expand All @@ -52,10 +54,12 @@ var defaultConfig = Config{
ConnRecycleTimeout: Duration{9 * time.Second},
}

// SetDefaultTimeToLive sets the default time to live (TTL) for the configuration.
func SetDefaultTimeToLive(ttl int) {
defaultConfig.DefaultTimeToLive = ttl
}

// SetDefaultTimeout sets the default timeout durations for the configuration.
func SetDefaultTimeout(connect, read, write, request, connRecycle time.Duration) {
defaultConfig.ConnectTimeout.Duration = connect
defaultConfig.ReadTimeout.Duration = read
Expand All @@ -64,10 +68,14 @@ func SetDefaultTimeout(connect, read, write, request, connRecycle time.Duration)
defaultConfig.ConnRecycleTimeout.Duration = connRecycle
}

// SetDefault updates the current Config to match the default Config.
func (c *Config) SetDefault() {
*c = defaultConfig
}

// validate checks if the required fields of the Config are correctly populated.
// It validates the Server field and checks if Appname and Namespace are specified.
// It returns an error if any of the above conditions are not met.
func (c *Config) validate() error {
if err := c.Server.Validate(); err != nil {
return err
Expand All @@ -78,6 +86,7 @@ func (c *Config) validate() error {
if len(c.Namespace) == 0 {
return fmt.Errorf("Config.Namespace not specified.")
}
/// TODO to validate others
// TODO to validate others
return nil
}

79 changes: 42 additions & 37 deletions pkg/client/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,66 @@
// limitations under the License.
//

// client is a package that handles various error situations in the Juno application.
package client

import (
"juno/internal/cli"
"juno/pkg/proto"
)

// Error variables for different scenarios in the application.
var (
ErrNoKey error
ErrUniqueKeyViolation error
ErrBadParam error
ErrConditionViolation error
ErrNoKey error // Error when no key is found.
ErrUniqueKeyViolation error // Error when there is a violation of a unique key.
ErrBadParam error // Error when a bad parameter is provided.
ErrConditionViolation error // Error when a condition violation occurs.

ErrBadMsg error
ErrNoStorage error
ErrRecordLocked error
ErrTTLExtendFailure error
ErrBusy error
ErrBadMsg error // Error when a bad message is encountered.
ErrNoStorage error // Error when no storage is available.
ErrRecordLocked error // Error when a record is locked.
ErrTTLExtendFailure error // Error when TTL extension fails.
ErrBusy error // Error when the server is busy.

ErrWriteFailure error
ErrInternal error
ErrOpNotSupported error
ErrWriteFailure error // Error when a write operation fails.
ErrInternal error // Error when an internal problem occurs.
ErrOpNotSupported error // Error when the operation is not supported.
)

// errorMapping is a map between different operation status and their corresponding errors.
var errorMapping map[proto.OpStatus]error

// init function initializes the error variables and the errorMapping map.
func init() {
ErrNoKey = &cli.Error{"no key"}
ErrUniqueKeyViolation = &cli.Error{"unique key violation"}
ErrBadParam = &cli.Error{"bad parameter"}
ErrConditionViolation = &cli.Error{"condition violation"} //version too old
ErrTTLExtendFailure = &cli.Error{"fail to extend TTL"}
ErrNoKey = &cli.Error{"no key"} // Error when the key does not exist.
ErrUniqueKeyViolation = &cli.Error{"unique key violation"} // Error when unique key constraint is violated.
ErrBadParam = &cli.Error{"bad parameter"} // Error when a bad parameter is passed.
ErrConditionViolation = &cli.Error{"condition violation"} // Error when there is a condition violation.
ErrTTLExtendFailure = &cli.Error{"fail to extend TTL"} // Error when TTL extension fails.

ErrBadMsg = &cli.RetryableError{"bad message"}
ErrNoStorage = &cli.RetryableError{"no storage"}
ErrRecordLocked = &cli.RetryableError{"record locked"}
ErrBusy = &cli.RetryableError{"server busy"}
ErrBadMsg = &cli.RetryableError{"bad message"} // Error when an inappropriate message is received.
ErrNoStorage = &cli.RetryableError{"no storage"} // Error when there is no storage available.
ErrRecordLocked = &cli.RetryableError{"record locked"} // Error when a record is locked.
ErrBusy = &cli.RetryableError{"server busy"} // Error when the server is busy.

ErrWriteFailure = &cli.Error{"write failure"}
ErrInternal = &cli.Error{"internal error"}
ErrOpNotSupported = &cli.Error{"Op not supported"}
ErrWriteFailure = &cli.Error{"write failure"} // Error when a write operation fails.
ErrInternal = &cli.Error{"internal error"} // Error when an internal error occurs.
ErrOpNotSupported = &cli.Error{"Op not supported"} // Error when the operation is not supported.

// Mapping between the operation status and the corresponding errors.
errorMapping = map[proto.OpStatus]error{
proto.OpStatusNoError: nil,
proto.OpStatusInconsistent: nil,
proto.OpStatusBadMsg: ErrBadMsg,
proto.OpStatusNoKey: ErrNoKey,
proto.OpStatusDupKey: ErrUniqueKeyViolation,
proto.OpStatusNoStorageServer: ErrNoStorage,
proto.OpStatusBadParam: ErrBadParam,
proto.OpStatusRecordLocked: ErrRecordLocked,
proto.OpStatusVersionConflict: ErrConditionViolation,
proto.OpStatusSSReadTTLExtendErr: ErrTTLExtendFailure,
proto.OpStatusCommitFailure: ErrWriteFailure,
proto.OpStatusBusy: ErrBusy,
proto.OpStatusNotSupported: ErrOpNotSupported,
proto.OpStatusNoError: nil, // Status when there is no error.
proto.OpStatusInconsistent: nil, // Status when there is an inconsistency.
proto.OpStatusBadMsg: ErrBadMsg, // Status when a bad message is received.
proto.OpStatusNoKey: ErrNoKey, // Status when the key is not present.
proto.OpStatusDupKey: ErrUniqueKeyViolation, // Status when unique key constraint is violated.
proto.OpStatusNoStorageServer: ErrNoStorage, // Status when there is no storage server available.
proto.OpStatusBadParam: ErrBadParam, // Status when a bad parameter is passed.
proto.OpStatusRecordLocked: ErrRecordLocked, // Status when a record is locked.
proto.OpStatusVersionConflict: ErrConditionViolation, // Status when there is a version conflict.
proto.OpStatusSSReadTTLExtendErr: ErrTTLExtendFailure, // Status when TTL extension fails.
proto.OpStatusCommitFailure: ErrWriteFailure, // Status when a commit operation fails.
proto.OpStatusBusy: ErrBusy, // Status when the server is busy.
proto.OpStatusNotSupported: ErrOpNotSupported, // Status when the operation is not supported.
}
}
Loading