Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

RFC-8: Add TCP protocol #8

Merged
merged 10 commits into from
Jul 17, 2021
Merged
Changes from 2 commits
Commits
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
90 changes: 90 additions & 0 deletions docs/rfcs/8-add-tcp-pair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
- Author: bokket [[email protected]](mailto:[email protected])
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
- Start Date: 2021-07-17
- RFC PR: [beyondstorage/go-endpoint#8](https://github.com/beyondstorage/go-endpoint/pull/8)
- Tracking Issue: [beyondstorage/go-endpoint/issues/7](https://github.com/beyondstorage/go-endpoint/issues/7)
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved

# RFC-8: Add Tcp pair
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved

Releated issue: [beyondstorage/go-endpoint/issues/7](https://github.com/beyondstorage/go-endpoint/issues/7)

## Background

hdfs usually use the `New(address string)` method to access a namenode node, the user will be the user running the code. If the address is an empty string, it will try to get the NameNode address from the Hadoop configuration file.

## Proposal

I suggest adding a pair to allow the user to specify the address.

- The `type` of `tcp` should be `String` and is a `const`
- The `format` of `ProtocolTcp` should follow [go-endpoint](https://github.com/beyondstorage/go-endpoint/blob/master/README.md)
- The `value` of `endpoint` should be parsed into `address include host and port`
- Now we don't have a pair operation on the `hdfs address` or tcp-like operation
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved

## Rationale

### Why not use hadoop configuration?
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved

We can specify the configuration of the path via `LoadHadoopConf`
If not specified, the default path `${hadoop_home}/conf` will be used

However, there is no guarantee that the path is wrong, and it is more common for users to use the namenode address directly.

## Compatibility

No compatibility issues at this time.

## Implementation

First add a `String` type with the name `ProtocolTcp` in `endpoint`.
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved

```go
const {
//ProtocolTcp is the file endpoint protocol
ProtocolTcp = "tcp"
}
```

Then implementing the Tcp method of endpoint

```go
func (p Endpoint) Tcp() (address string) {
if p.protocol != ProtocolTcp {
panic(Error{
Op: "tcp",
Err: ErrInvalidValue,
Protocol: p.protocol,
Values: p.args,
})
}
//It must be host:port
return p.args.(string)
}
```

Then implementing Parse and NewTcp methods

```go
func Parse(cfg string) (Provider, error) {
s := strings.Split(cfg, ":")

switch s[0] {
.....
case ProtocolTcp:
//Handle tcp connection (hdfs)
return NewTcp(s[1]),nil
default:
return Endpoint{}, &Error{"parse", ErrUnsupportedProtocol, s[0], nil}
}
}
```



```go
func NewTcp(address string) Endpoint {
return Endpoint{
protocol: ProtocolTcp,
args: path,
}
}
```