Beispiel #1
0
// Next implements Execution Next interface.
func (e *ShowDDLExec) Next() (*Row, error) {
	if e.done {
		return nil, nil
	}

	txn, err := e.ctx.GetTxn(false)
	if err != nil {
		return nil, errors.Trace(err)
	}

	info, err := inspectkv.GetDDLInfo(txn)
	if err != nil {
		return nil, errors.Trace(err)
	}

	rowData := []interface{}{
		info.SchemaVer,
		"",
		"",
	}
	if info.Owner != nil {
		rowData[1] = info.Owner.String()
	}
	if info.Job != nil {
		rowData[2] = info.Job.String()
	}
	row := &Row{}
	row.Data = rowData
	for i, f := range e.fields {
		f.Expr.SetValue(rowData[i])
	}
	e.done = true

	return row, nil
}
Beispiel #2
0
func (s *testSuite) TestAdmin(c *C) {
	defer testleak.AfterTest(c)()
	tk := testkit.NewTestKit(c, s.store)
	tk.MustExec("use test")
	tk.MustExec("drop table if exists admin_test")
	tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1))")
	tk.MustExec("insert admin_test (c1) values (1),(2),(NULL)")
	r, err := tk.Exec("admin show ddl")
	c.Assert(err, IsNil)
	row, err := r.Next()
	c.Assert(err, IsNil)
	c.Assert(row.Data, HasLen, 6)
	txn, err := s.store.Begin()
	c.Assert(err, IsNil)
	ddlInfo, err := inspectkv.GetDDLInfo(txn)
	c.Assert(err, IsNil)
	c.Assert(row.Data[0].GetInt64(), Equals, ddlInfo.SchemaVer)
	rowOwnerInfos := strings.Split(row.Data[1].GetString(), ",")
	ownerInfos := strings.Split(ddlInfo.Owner.String(), ",")
	c.Assert(rowOwnerInfos[0], Equals, ownerInfos[0])
	c.Assert(row.Data[2].GetString(), Equals, "")
	bgInfo, err := inspectkv.GetBgDDLInfo(txn)
	c.Assert(err, IsNil)
	c.Assert(row.Data[3].GetInt64(), Equals, bgInfo.SchemaVer)
	rowOwnerInfos = strings.Split(row.Data[4].GetString(), ",")
	ownerInfos = strings.Split(bgInfo.Owner.String(), ",")
	c.Assert(rowOwnerInfos[0], Equals, ownerInfos[0])
	c.Assert(row.Data[5].GetString(), Equals, "")
	row, err = r.Next()
	c.Assert(err, IsNil)
	c.Assert(row, IsNil)

	// check table test
	tk.MustExec("create table admin_test1 (c1 int, c2 int default 1, index (c1))")
	tk.MustExec("insert admin_test1 (c1) values (21),(22)")
	r, err = tk.Exec("admin check table admin_test, admin_test1")
	c.Assert(err, IsNil)
	c.Assert(r, IsNil)
	// error table name
	r, err = tk.Exec("admin check table admin_test_error")
	c.Assert(err, NotNil)
	// different index values
	ctx := tk.Se.(context.Context)
	domain := sessionctx.GetDomain(ctx)
	is := domain.InfoSchema()
	c.Assert(is, NotNil)
	tb, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("admin_test"))
	c.Assert(err, IsNil)
	c.Assert(tb.Indices(), HasLen, 1)
	_, err = tb.Indices()[0].Create(txn, types.MakeDatums(int64(10)), 1)
	c.Assert(err, IsNil)
	err = txn.Commit()
	c.Assert(err, IsNil)
	r, err = tk.Exec("admin check table admin_test")
	c.Assert(err, NotNil)
}
Beispiel #3
0
// Next implements Executor Next interface.
func (e *ShowDDLExec) Next() (*Row, error) {
	if e.done {
		return nil, nil
	}

	txn, err := e.ctx.GetTxn(false)
	if err != nil {
		return nil, errors.Trace(err)
	}

	ddlInfo, err := inspectkv.GetDDLInfo(txn)
	if err != nil {
		return nil, errors.Trace(err)
	}
	bgInfo, err := inspectkv.GetBgDDLInfo(txn)
	if err != nil {
		return nil, errors.Trace(err)
	}

	var ddlOwner, ddlJob string
	if ddlInfo.Owner != nil {
		ddlOwner = ddlInfo.Owner.String()
	}
	if ddlInfo.Job != nil {
		ddlJob = ddlInfo.Job.String()
	}

	var bgOwner, bgJob string
	if bgInfo.Owner != nil {
		bgOwner = bgInfo.Owner.String()
	}
	if bgInfo.Job != nil {
		bgJob = bgInfo.Job.String()
	}

	row := &Row{}
	row.Data = types.MakeDatums(
		ddlInfo.SchemaVer,
		ddlOwner,
		ddlJob,
		bgInfo.SchemaVer,
		bgOwner,
		bgJob,
	)
	for i, f := range e.fields {
		f.Expr.SetValue(row.Data[i].GetValue())
	}
	e.done = true

	return row, nil
}
Beispiel #4
0
func (s *testSuite) TestAdmin(c *C) {
	tk := testkit.NewTestKit(c, s.store)
	tk.MustExec("use test")
	tk.MustExec("drop table if exists admin_test")
	tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1))")
	tk.MustExec("insert admin_test (c1) values (1),(2),(NULL)")
	r, err := tk.Exec("admin show ddl")
	c.Assert(err, IsNil)
	row, err := r.Next()
	c.Assert(err, IsNil)
	c.Assert(row.Data, HasLen, 3)
	txn, err := s.store.Begin()
	c.Assert(err, IsNil)
	ddlInfo, err := inspectkv.GetDDLInfo(txn)
	c.Assert(err, IsNil)
	c.Assert(row.Data[0], Equals, ddlInfo.SchemaVer)
	c.Assert(row.Data[1], DeepEquals, ddlInfo.Owner.String())
	c.Assert(row.Data[2], DeepEquals, "")
	row, err = r.Next()
	c.Assert(err, IsNil)
	c.Assert(row, IsNil)

	// check table test
	tk.MustExec("create table admin_test1 (c1 int, c2 int default 1, index (c1))")
	tk.MustExec("insert admin_test1 (c1) values (21),(22)")
	r, err = tk.Exec("admin check table admin_test, admin_test1")
	c.Assert(err, IsNil)
	c.Assert(r, IsNil)
	// error table name
	r, err = tk.Exec("admin check table admin_test_error")
	c.Assert(err, NotNil)
	// different index values
	domain, err := domain.NewDomain(s.store, 1*time.Second)
	c.Assert(err, IsNil)
	is := domain.InfoSchema()
	c.Assert(is, NotNil)
	tb, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("admin_test"))
	c.Assert(err, IsNil)
	c.Assert(tb.Indices(), HasLen, 1)
	err = tb.Indices()[0].X.Create(txn, []interface{}{int64(10)}, 1)
	c.Assert(err, IsNil)
	err = txn.Commit()
	c.Assert(err, IsNil)
	r, err = tk.Exec("admin check table admin_test")
	c.Assert(err, NotNil)
}
Beispiel #5
0
// Stat returns the DDL statistics.
func (d *ddl) Stats() (map[string]interface{}, error) {
	var info *inspectkv.DDLInfo
	err := kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
		var err1 error
		info, err1 = inspectkv.GetDDLInfo(txn)

		return errors.Trace(err1)
	})
	if err != nil {
		return nil, errors.Trace(err)
	}

	m := make(map[string]interface{})
	m[ddlServerID] = d.uuid

	m[ddlSchemaVersion] = info.SchemaVer

	if info.Owner != nil {
		m[ddlOwnerID] = info.Owner.OwnerID
		// LastUpdateTS uses nanosecond.
		m[ddlOwnerLastUpdateTS] = info.Owner.LastUpdateTS / 1e9
	}

	if info.Job != nil {
		m[ddlJobID] = info.Job.ID
		m[ddlJobAction] = info.Job.Type.String()
		m[ddlJobLastUpdateTS] = info.Job.LastUpdateTS / 1e9
		m[ddlJobState] = info.Job.State.String()
		m[ddlJobError] = info.Job.Error
		m[ddlJobSchemaState] = info.Job.SchemaState.String()
		m[ddlJobSchemaID] = info.Job.SchemaID
		m[ddlJobTableID] = info.Job.TableID
		m[ddlJobSnapshotVer] = info.Job.SnapshotVer
		m[ddlJobReorgHandle] = info.ReorgHandle
		m[ddlJobArgs] = info.Job.Args
	}

	return m, nil
}