Skip to content

Commit 80e8035

Browse files
Avoid duplicate ocbinds schema loading (sonic-net#73)
Introduced a new function ocbinds.GetSchema(), which is equivalent of the generated function ocbinds.Schema(), but loads the schema only once. Translib request_binder and transformer are changed to use the new GetSchema() function. Avoids duplicate schema loads during init. Signed-off-by: Sachin Holla <sachin.holla@broadcom.com> Co-authored-by: anand-kumar-subramanian <51383315+anand-kumar-subramanian@users.noreply.github.com>
1 parent 3036d3a commit 80e8035

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

translib/ocbinds/schema.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// Copyright 2021 Broadcom. The term Broadcom refers to Broadcom Inc. and/or //
4+
// its subsidiaries. //
5+
// //
6+
// Licensed under the Apache License, Version 2.0 (the "License"); //
7+
// you may not use this file except in compliance with the License. //
8+
// You may obtain a copy of the License at //
9+
// //
10+
// http://www.apache.org/licenses/LICENSE-2.0 //
11+
// //
12+
// Unless required by applicable law or agreed to in writing, software //
13+
// distributed under the License is distributed on an "AS IS" BASIS, //
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
15+
// See the License for the specific language governing permissions and //
16+
// limitations under the License. //
17+
// //
18+
////////////////////////////////////////////////////////////////////////////////
19+
20+
package ocbinds
21+
22+
import (
23+
"github.com/openconfig/ygot/ytypes"
24+
)
25+
26+
// GetSchema is equivalent of the Schema function, but avoids
27+
// UnzipSchema call. Reuses the SchemaTree loaded during init.
28+
func GetSchema() (*ytypes.Schema, error) {
29+
return &ytypes.Schema{
30+
Root: &Device{},
31+
SchemaTree: SchemaTree,
32+
Unmarshal: Unmarshal,
33+
}, nil
34+
}

translib/request_binder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func init() {
5151
func initSchema() {
5252
log.Flush()
5353
var err error
54-
if ygSchema, err = ocbinds.Schema(); err != nil {
54+
if ygSchema, err = ocbinds.GetSchema(); err != nil {
5555
panic("Error in getting the schema: " + err.Error())
5656
}
5757
}

translib/transformer/xlate_to_db.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
log "github.com/golang/glog"
3333
)
3434

35-
var ocbSch, _ = ocbinds.Schema()
35+
var ocbSch, _ = ocbinds.GetSchema()
3636

3737
/* Fill redis-db map with field & value info */
3838
func dataToDBMapAdd(tableName string, dbKey string, result map[string]map[string]db.Value, field string, value string) {

0 commit comments

Comments
 (0)