github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/plugin/spi.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package plugin
    15  
    16  import (
    17  	"context"
    18  	"reflect"
    19  	"unsafe"
    20  
    21  	"github.com/whtcorpsinc/milevadb/stochastikctx/variable"
    22  )
    23  
    24  const (
    25  	// LibrarySuffix defines MilevaDB plugin's file suffix.
    26  	LibrarySuffix = ".so"
    27  	// ManifestSymbol defines MilevaDB plugin's entrance symbol.
    28  	// Plugin take manifest info from this symbol.
    29  	ManifestSymbol = "PluginManifest"
    30  )
    31  
    32  // Manifest describes plugin info and how it can do by plugin itself.
    33  type Manifest struct {
    34  	Name           string
    35  	Description    string
    36  	RequireVersion map[string]uint16
    37  	License        string
    38  	BuildTime      string
    39  	SysVars        map[string]*variable.SysVar
    40  	// Validate defines the validate logic for plugin.
    41  	// returns error will stop load plugin process and MilevaDB startup.
    42  	Validate func(ctx context.Context, manifest *Manifest) error
    43  	// OnInit defines the plugin init logic.
    44  	// it will be called after petri init.
    45  	// return error will stop load plugin process and MilevaDB startup.
    46  	OnInit func(ctx context.Context, manifest *Manifest) error
    47  	// OnShutDown defines the plugin cleanup logic.
    48  	// return error will write log and continue shutdown.
    49  	OnShutdown func(ctx context.Context, manifest *Manifest) error
    50  	// OnFlush defines flush logic after executed `flush milevadb plugins`.
    51  	// it will be called after OnInit.
    52  	// return error will write log and continue watch following flush.
    53  	OnFlush      func(ctx context.Context, manifest *Manifest) error
    54  	flushWatcher *flushWatcher
    55  
    56  	Version uint16
    57  	HoTT    HoTT
    58  }
    59  
    60  // ExportManifest exports a manifest to MilevaDB as a known format.
    61  // it just casts sub-manifest to manifest.
    62  func ExportManifest(m interface{}) *Manifest {
    63  	v := reflect.ValueOf(m)
    64  	return (*Manifest)(unsafe.Pointer(v.Pointer()))
    65  }
    66  
    67  // AuthenticationManifest presents a sub-manifest that every audit plugin must provide.
    68  type AuthenticationManifest struct {
    69  	Manifest
    70  	AuthenticateUser             func()
    71  	GenerateAuthenticationString func()
    72  	ValidateAuthenticationString func()
    73  	SetSalt                      func()
    74  }
    75  
    76  // SchemaManifest presents a sub-manifest that every schemaReplicant plugins must provide.
    77  type SchemaManifest struct {
    78  	Manifest
    79  }
    80  
    81  // DaemonManifest presents a sub-manifest that every DaemonManifest plugins must provide.
    82  type DaemonManifest struct {
    83  	Manifest
    84  }