Skip to content

Commit

Permalink
Revert "Merge pull request grpc#2249 from AVVS/fix/perf-issues"
Browse files Browse the repository at this point in the history
This reverts commit b364135, reversing
changes made to c84b4f9.
  • Loading branch information
Cedric Kassen committed Jul 11, 2023
1 parent 1cc36e8 commit ef19f1c
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 242 deletions.
6 changes: 2 additions & 4 deletions packages/grpc-js/package.json
@@ -1,9 +1,7 @@
{
"name": "@grpc/grpc-js",
"version": "1.8.14",
"name": "@mittwald/grpc-js",
"version": "1.0.0",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
"main": "build/src/index.js",
"engines": {
"node": "^8.13.0 || >=10.10.0"
Expand Down
Expand Up @@ -3,27 +3,43 @@

// Original file: proto/channelz.proto

export enum _grpc_channelz_v1_ChannelConnectivityState_State {
UNKNOWN = 0,
IDLE = 1,
CONNECTING = 2,
READY = 3,
TRANSIENT_FAILURE = 4,
SHUTDOWN = 5,
}
export const _grpc_channelz_v1_ChannelConnectivityState_State = {
UNKNOWN: 'UNKNOWN',
IDLE: 'IDLE',
CONNECTING: 'CONNECTING',
READY: 'READY',
TRANSIENT_FAILURE: 'TRANSIENT_FAILURE',
SHUTDOWN: 'SHUTDOWN',
} as const;

export type _grpc_channelz_v1_ChannelConnectivityState_State =
| 'UNKNOWN'
| 0
| 'IDLE'
| 1
| 'CONNECTING'
| 2
| 'READY'
| 3
| 'TRANSIENT_FAILURE'
| 4
| 'SHUTDOWN'
| 5

export type _grpc_channelz_v1_ChannelConnectivityState_State__Output = typeof _grpc_channelz_v1_ChannelConnectivityState_State[keyof typeof _grpc_channelz_v1_ChannelConnectivityState_State]

/**
* These come from the specified states in this document:
* https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md
*/
export interface ChannelConnectivityState {
'state'?: (_grpc_channelz_v1_ChannelConnectivityState_State | keyof typeof _grpc_channelz_v1_ChannelConnectivityState_State);
'state'?: (_grpc_channelz_v1_ChannelConnectivityState_State);
}

/**
* These come from the specified states in this document:
* https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md
*/
export interface ChannelConnectivityState__Output {
'state': (keyof typeof _grpc_channelz_v1_ChannelConnectivityState_State);
'state': (_grpc_channelz_v1_ChannelConnectivityState_State__Output);
}
Expand Up @@ -9,12 +9,30 @@ import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__O
/**
* The supported severity levels of trace events.
*/
export enum _grpc_channelz_v1_ChannelTraceEvent_Severity {
CT_UNKNOWN = 0,
CT_INFO = 1,
CT_WARNING = 2,
CT_ERROR = 3,
}
export const _grpc_channelz_v1_ChannelTraceEvent_Severity = {
CT_UNKNOWN: 'CT_UNKNOWN',
CT_INFO: 'CT_INFO',
CT_WARNING: 'CT_WARNING',
CT_ERROR: 'CT_ERROR',
} as const;

/**
* The supported severity levels of trace events.
*/
export type _grpc_channelz_v1_ChannelTraceEvent_Severity =
| 'CT_UNKNOWN'
| 0
| 'CT_INFO'
| 1
| 'CT_WARNING'
| 2
| 'CT_ERROR'
| 3

/**
* The supported severity levels of trace events.
*/
export type _grpc_channelz_v1_ChannelTraceEvent_Severity__Output = typeof _grpc_channelz_v1_ChannelTraceEvent_Severity[keyof typeof _grpc_channelz_v1_ChannelTraceEvent_Severity]

/**
* A trace event is an interesting thing that happened to a channel or
Expand All @@ -28,7 +46,7 @@ export interface ChannelTraceEvent {
/**
* the severity of the trace event
*/
'severity'?: (_grpc_channelz_v1_ChannelTraceEvent_Severity | keyof typeof _grpc_channelz_v1_ChannelTraceEvent_Severity);
'severity'?: (_grpc_channelz_v1_ChannelTraceEvent_Severity);
/**
* When this event occurred.
*/
Expand Down Expand Up @@ -56,7 +74,7 @@ export interface ChannelTraceEvent__Output {
/**
* the severity of the trace event
*/
'severity': (keyof typeof _grpc_channelz_v1_ChannelTraceEvent_Severity);
'severity': (_grpc_channelz_v1_ChannelTraceEvent_Severity__Output);
/**
* When this event occurred.
*/
Expand Down
52 changes: 29 additions & 23 deletions packages/grpc-js/src/metadata.ts
Expand Up @@ -49,14 +49,13 @@ function validate(key: string, value?: MetadataValue): void {
if (!isLegalKey(key)) {
throw new Error('Metadata key "' + key + '" contains illegal characters');
}

if (value !== null && value !== undefined) {
if (isBinaryKey(key)) {
if (!Buffer.isBuffer(value)) {
if (!(value instanceof Buffer)) {
throw new Error("keys that end with '-bin' must have Buffer values");
}
} else {
if (Buffer.isBuffer(value)) {
if (value instanceof Buffer) {
throw new Error(
"keys that don't end with '-bin' must have String values"
);
Expand Down Expand Up @@ -90,8 +89,12 @@ export class Metadata {
protected internalRepr: MetadataObject = new Map<string, MetadataValue[]>();
private options: MetadataOptions;

constructor(options: MetadataOptions = {}) {
this.options = options;
constructor(options?: MetadataOptions) {
if (options === undefined) {
this.options = {};
} else {
this.options = options;
}
}

/**
Expand Down Expand Up @@ -134,7 +137,7 @@ export class Metadata {
*/
remove(key: string): void {
key = normalizeKey(key);
// validate(key);
validate(key);
this.internalRepr.delete(key);
}

Expand All @@ -145,7 +148,7 @@ export class Metadata {
*/
get(key: string): MetadataValue[] {
key = normalizeKey(key);
// validate(key);
validate(key);
return this.internalRepr.get(key) || [];
}

Expand All @@ -157,12 +160,12 @@ export class Metadata {
getMap(): { [key: string]: MetadataValue } {
const result: { [key: string]: MetadataValue } = {};

for (const [key, values] of this.internalRepr) {
this.internalRepr.forEach((values, key) => {
if (values.length > 0) {
const v = values[0];
result[key] = Buffer.isBuffer(v) ? Buffer.from(v) : v;
result[key] = v instanceof Buffer ? v.slice() : v;
}
}
});
return result;
}

Expand All @@ -184,7 +187,7 @@ export class Metadata {
});

newInternalRepr.set(key, clonedValue);
}
};

return newMetadata;
}
Expand All @@ -197,13 +200,13 @@ export class Metadata {
* @param other A Metadata object.
*/
merge(other: Metadata): void {
for (const [key, values] of other.internalRepr) {
other.internalRepr.forEach((values, key) => {
const mergedValue: MetadataValue[] = (
this.internalRepr.get(key) || []
).concat(values);

this.internalRepr.set(key, mergedValue);
}
});
}

setOptions(options: MetadataOptions) {
Expand All @@ -220,13 +223,17 @@ export class Metadata {
toHttp2Headers(): http2.OutgoingHttpHeaders {
// NOTE: Node <8.9 formats http2 headers incorrectly.
const result: http2.OutgoingHttpHeaders = {};

for (const [key, values] of this.internalRepr) {
this.internalRepr.forEach((values, key) => {
// We assume that the user's interaction with this object is limited to
// through its public API (i.e. keys and values are already validated).
result[key] = values.map(bufToString);
}

result[key] = values.map((value) => {
if (value instanceof Buffer) {
return value.toString('base64');
} else {
return value;
}
});
});
return result;
}

Expand All @@ -241,7 +248,7 @@ export class Metadata {
*/
toJSON() {
const result: { [key: string]: MetadataValue[] } = {};
for (const [key, values] of this.internalRepr) {
for (const [key, values] of this.internalRepr.entries()) {
result[key] = values;
}
return result;
Expand All @@ -254,10 +261,10 @@ export class Metadata {
*/
static fromHttp2Headers(headers: http2.IncomingHttpHeaders): Metadata {
const result = new Metadata();
for (const key of Object.keys(headers)) {
Object.keys(headers).forEach((key) => {
// Reserved headers (beginning with `:`) are not valid keys.
if (key.charAt(0) === ':') {
continue;
return;
}

const values = headers[key];
Expand Down Expand Up @@ -292,8 +299,7 @@ export class Metadata {
)}. For more information see https://github.com/grpc/grpc-node/issues/1173`;
log(LogVerbosity.ERROR, message);
}
}

});
return result;
}
}
Expand Down

0 comments on commit ef19f1c

Please sign in to comment.