зеркало из https://github.com/github/vitess-gh.git
* Purge logs without panicking * Purge logs without panicking * try moving the goroutine to the func itself --------- Signed-off-by: Andrew Mason <andrew@planetscale.com>
This commit is contained in:
Родитель
5e9de1f9fe
Коммит
ab1d0fe888
|
@ -70,6 +70,7 @@ func main() {
|
|||
acl.RegisterFlags(fs)
|
||||
servenv.RegisterMySQLServerFlags(fs)
|
||||
_flag.Parse(fs)
|
||||
logutil.PurgeLogs()
|
||||
for _, filename := range _flag.Args() {
|
||||
fmt.Printf("processing: %s\n", filename)
|
||||
if err := processFile(filename); err != nil {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
_flag "vitess.io/vitess/go/internal/flag"
|
||||
"vitess.io/vitess/go/vt/logutil"
|
||||
)
|
||||
|
||||
var configFile string
|
||||
|
@ -14,6 +15,7 @@ func Main() *cobra.Command {
|
|||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
_flag.TrickGlog()
|
||||
logutil.PurgeLogs()
|
||||
},
|
||||
Run: func(cmd *cobra.Command, _ []string) { cmd.Help() },
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"vitess.io/vitess/go/trace"
|
||||
"vitess.io/vitess/go/vt/log"
|
||||
"vitess.io/vitess/go/vt/logutil"
|
||||
"vitess.io/vitess/go/vt/servenv"
|
||||
"vitess.io/vitess/go/vt/vtadmin"
|
||||
"vitess.io/vitess/go/vt/vtadmin/cache"
|
||||
|
@ -58,6 +59,7 @@ var (
|
|||
Use: "vtadmin",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
_flag.TrickGlog()
|
||||
logutil.PurgeLogs()
|
||||
|
||||
if opts.EnableTracing || httpOpts.EnableTracing {
|
||||
startTracing(cmd)
|
||||
|
|
|
@ -184,6 +184,8 @@ func run() (*results, error) {
|
|||
_flag.Parse(fs)
|
||||
args := _flag.Args()
|
||||
|
||||
logutil.PurgeLogs()
|
||||
|
||||
if len(args) == 0 {
|
||||
pflag.Usage()
|
||||
return nil, errors.New("no arguments provided. See usage above")
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"vitess.io/vitess/go/trace"
|
||||
"vitess.io/vitess/go/vt/logutil"
|
||||
"vitess.io/vitess/go/vt/servenv"
|
||||
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
|
||||
)
|
||||
|
@ -49,6 +50,7 @@ var (
|
|||
// We use PersistentPreRun to set up the tracer, grpc client, and
|
||||
// command context for every command.
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
logutil.PurgeLogs()
|
||||
traceCloser = trace.StartTracing("vtctldclient")
|
||||
if VtctldClientProtocol != "local" {
|
||||
if err := ensureServerArg(); err != nil {
|
||||
|
|
|
@ -147,6 +147,7 @@ func main() {
|
|||
}
|
||||
|
||||
pflag.Parse()
|
||||
logutil.PurgeLogs()
|
||||
|
||||
if help || pflag.Arg(0) == "help" {
|
||||
pflag.Usage()
|
||||
|
|
|
@ -127,7 +127,10 @@ func PurgeLogs() {
|
|||
logDir := f.Value.String()
|
||||
program := filepath.Base(os.Args[0])
|
||||
ticker := time.NewTicker(purgeLogsInterval)
|
||||
for range ticker.C {
|
||||
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
Copyright 2019 The Vitess Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package servenv
|
||||
|
||||
import (
|
||||
"vitess.io/vitess/go/vt/logutil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
OnInit(func() {
|
||||
go logutil.PurgeLogs()
|
||||
})
|
||||
|
||||
}
|
|
@ -319,6 +319,8 @@ func ParseFlags(cmd string) {
|
|||
_flag.Usage()
|
||||
log.Exitf("%s doesn't take any positional arguments, got '%s'", cmd, strings.Join(args, " "))
|
||||
}
|
||||
|
||||
logutil.PurgeLogs()
|
||||
}
|
||||
|
||||
// GetFlagSetFor returns the flag set for a given command.
|
||||
|
@ -348,6 +350,8 @@ func ParseFlagsWithArgs(cmd string) []string {
|
|||
log.Exitf("%s expected at least one positional argument", cmd)
|
||||
}
|
||||
|
||||
logutil.PurgeLogs()
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче