etcd 连接上之后无法使用 get 获取对应的值
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 546
- Forks
- 76
- Avg merge
- 22h 46m
- Merged PRs (30d)
- 13
Description
1. 本地启动 etcd
PS E:\etcd> .\bin\etcd.exe
2020-12-19 18:10:58.844408 I | etcdmain: etcd Version: 3.3.13
2020-12-19 18:10:58.881419 I | etcdmain: Git SHA: Not provided (use ./build instead of go build)
2020-12-19 18:10:58.882408 I | etcdmain: Go Version: go1.14.2
2020-12-19 18:10:58.882408 I | etcdmain: Go OS/Arch: windows/amd64
2020-12-19 18:10:58.893410 I | etcdmain: setting maximum number of CPUs to 8, total number of available CPUs is 8
2020-12-19 18:10:58.894421 N | etcdmain: failed to detect default host (default host not supported on windows_amd64)
2020-12-19 18:10:58.894421 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2020-12-19 18:10:58.907408 I | embed: listening for peers on http://localhost:2380
2020-12-19 18:10:58.909409 I | embed: listening for client requests on localhost:2379
2020-12-19 18:10:58.969440 I | etcdserver: name = default
2020-12-19 18:10:58.970409 I | etcdserver: data dir = default.etcd
2020-12-19 18:10:58.970409 I | etcdserver: member dir = default.etcd\member
2020-12-19 18:10:58.970409 I | etcdserver: heartbeat = 100ms
2020-12-19 18:10:58.971410 I | etcdserver: election = 1000ms
2020-12-19 18:10:58.971410 I | etcdserver: snapshot count = 100000
2020-12-19 18:10:58.972408 I | etcdserver: advertise client URLs = http://localhost:2379
2020-12-19 18:10:58.972408 I | etcdserver: initial advertise peer URLs = http://localhost:2380
2020-12-19 18:10:58.972408 I | etcdserver: initial cluster = default=http://localhost:2380
2020-12-19 18:10:59.001407 I | wal: releasing file lock to rename "default.etcd\\member\\wal.tmp" to "default.etcd\\member\\wal"
2020-12-19 18:10:59.059615 I | etcdserver: starting member 8e9e05c52164694d in cluster cdf818194e3a8c32
2020-12-19 18:10:59.060407 I | raft: 8e9e05c52164694d became follower at term 0
2020-12-19 18:10:59.060407 I | raft: newRaft 8e9e05c52164694d [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2020-12-19 18:10:59.061408 I | raft: 8e9e05c52164694d became follower at term 1
2020-12-19 18:10:59.185408 W | auth: simple token is not cryptographically signed
2020-12-19 18:10:59.267407 I | etcdserver: starting server... [version: 3.3.13, cluster version: to_be_decided]
2020-12-19 18:10:59.268408 I | etcdserver: 8e9e05c52164694d as single-node; fast-forwarding 9 ticks (election ticks 10)
2020-12-19 18:10:59.268408 E | etcdserver: cannot monitor file descriptor usage (cannot get FDUsage on windows)
2020-12-19 18:10:59.269409 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32
2020-12-19 18:11:00.080662 I | raft: 8e9e05c52164694d is starting a new election at term 1
2020-12-19 18:11:00.080662 I | raft: 8e9e05c52164694d became candidate at term 2
2020-12-19 18:11:00.081663 I | raft: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2
2020-12-19 18:11:00.081663 I | raft: 8e9e05c52164694d became leader at term 2
2020-12-19 18:11:00.103665 I | raft: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
2020-12-19 18:11:00.103665 I | etcdserver: setting up the initial cluster version to 3.3
2020-12-19 18:11:00.125663 N | etcdserver/membership: set the initial cluster version to 3.3
2020-12-19 18:11:00.135665 I | etcdserver/api: enabled capabilities for version 3.3
2020-12-19 18:11:00.135665 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
2020-12-19 18:11:00.136666 I | embed: ready to serve client requests
2020-12-19 18:11:00.137697 N | embed: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
2. 使用 etcdctl 添加一个键值对
PS E:\etcd\bin> .\etcdctl.exe set helloKey helloEtcd
helloEtcd
PS E:\etcd\bin> .\etcdctl.exe get helloKey
helloEtcd
3. 测试的脚本 main.js
const { Etcd3 } = require('etcd3');
const client = new Etcd3({ hosts: ['http://127.0.0.1:2379'] });
console.log(client);
(async () => {
const fooValue = await client.get('helloKey').string()
console.log(fooValue)
})();
4. 执行 main.js 的结果
PS E:\policy-ops\etcd-play> node .\main.js
Etcd3 {
prefix: <Buffer >,
pool: ConnectionPool {
options: { hosts: [Array] },
callOptionsFactory: undefined,
globalPolicy: RetryPolicy {
options: [Object],
executor: [ExecuteWrapper],
onGiveUpEmitter: [EventEmitter],
onRetryEmitter: [EventEmitter],
onSuccess: [Function],
onFailure: [Function],
onRetry: [Function],
onGiveUp: [Function]
},
authenticator: Authenticator {
options: [Object],
credentials: [InsecureChannelCredentialsImpl],
awaitingMetadata: null
},
hosts: [ [Host] ]
},
options: { hosts: [ 'http://127.0.0.1:2379' ] },
kv: KVClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
},
leaseClient: LeaseClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
},
watchClient: WatchClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
},
nsApplicator: NSApplicator { prefix: <Buffer > },
watchManager: WatchManager {
client: WatchClient { client: [ConnectionPool] },
backoff: ExponentialBackoff { attempt: 0, delay: 0, options: [Object] },
state: 0,
watchers: [],
expectedClosers: Set {},
initialBackoff: ExponentialBackoff { attempt: 0, delay: 0, options: [Object] }
},
auth: AuthClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
},
maintenance: MaintenanceClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
},
cluster: ClusterClient {
client: ConnectionPool {
options: [Object],
callOptionsFactory: undefined,
globalPolicy: [RetryPolicy],
authenticator: [Authenticator],
hosts: [Array]
}
}
}
null
PS E:\policy-ops\etcd-play>
5. 问题
从第4步来看console.log(fooValue) 输出是 null,正确的值是 helloEtcd 才对
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reported reproduction in main.js against the local etcd instance, comparing client.get('helloKey').string() with the successful etcdctl get command. Trace the get and string entry points in the TypeScript client to determine why the existing key becomes null. Done means the script prints helloEtcd for the same key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100