# TiSpark Knowledge Base

## TiSpark makes too many requests to TiKV, causing requests to be Outdated

## Affected versions

[2.0]

[2.1.0, v2.1.9]

[v2.3.0, v2.3.11]

Whether v2.3.12 can be resolved is uncertain, refer to [Issue-1877](https://github.com/pingcap/tispark/issues/1877).

## Problem Description

When spark has more cores and scans more data from tikv, there is a chance that the store coprocessor cpu will spike and the tikv logs will report outdated.

## Workaround

There are several ways to mitigate this problem

Reduce spark.tispark.index.scan\_concurrency and spark.tispark.table.scan_concurrency to reduce the number of simultaneous requests to tikv from a single executor

Reduce spark core, reduce the number of spark executors, reduce the number of requests to tikv

## Cause of the problem

Currently, TiSpark does not limit the flow of Coprocessor requests to TiKV. When there are more Spark cores and more data needs to be scanned from TiKV, TiSpark may send too many requests to TiKV at the same time, and TiKV cannot process them in time. Eventually, the requests are Outdated.

TiSpark is planning to do flow limiting, please refer to [isuue 1887](https://github.com/pingcap/tispark/issues/1877).

## Tags

TiSpark, flow control

## Related materials

[OnCall-2269](https://internal.pingcap.net/jira/browse/ONCALL-2269).

## Added by

Liangliang Gu

---------------------------------------------------

## **TiSpark reads Chinese data with garbled code**

---------------------------------------------------

## Affected versions - issue 2

All versions

## Problem Description - issue 2

When reading data from TiDB with TiSpark, Chinese characters appear as soft gibberish

## Solution - issue 2

Add `-Dfile.encoding=UTF-8` to the jvm startup parameters of driver and executor

After spark-submit, add the following 2 parameters

```
--conf "spark.driver.extraJavaOptions=-Dfile.encoding=UTF-8"

--conf "spark.executor.extraJavaOptions=-Dfile.encoding=UTF-8"
```

Or add to conf/spark-defaults.conf

```
spark.driver.extraJavaOptions -Dfile.encoding=UTF-8

spark.executor.extraJavaOptions -Dfile.encoding=UTF-8
```

## Cause of the problem - issue 2

TiSpark uses the Default Charset of the JVM, which depends on the locale and charset of the operating system, and when the Default Charset of the JVM does not match the encoding of the data to be parsed When the default charset of the JVM does not match the encoding of the data to be parsed, garbled code will appear.

By passing the system variable file.encoding when starting the JVM, you can specify the JVM Default Charset to be UTF-8 to avoid Chinese garbled code problems.

## Tags - issue 2

TiSpark, encoding

## Related materials - issue 2

[OnCall-2248](https://internal.pingcap.net/jira/browse/ONCALL-2248)

## Added by - issue 2

Gu Liangliang

---------------------------------------------------

## **TiSpark Netty OutOfDirectMemoryError**

---------------------------------------------------

## Affected versions - issue 3

All versions

## Problem Description - issue 3

TiSpark encounters this error when reading data

Caused by: shade.io.netty.handler.codec.DecoderException: shade.io.netty.util.internal.OutOfDirectMemoryError

## Solution - issue 3

Add the following 2 arguments after spark-submit

```
--conf "spark.driver.extraJavaOptions=-Dshade.io.netty.allocator.type=unpooled"

--conf "spark.executor.extraJavaOptions=-Dshade.io.netty.allocator.type=unpooled"
```

Or add to conf/spark-defaults.conf

```
spark.driver.extraJavaOptions -Dshade.io.netty.allocator.type=unpooled

spark.executor.extraJavaOptions -Dshade.io.netty.allocator.type=unpooled
```

## Cause of the problem - issue 3

In the version of Netty used by TiSpark, there is something wrong with Netty's PoolThreadCache, it will keep some unused memory and not release it, so when requesting memory again, it will not be requested, but there is actually available memory.

You can get around this by setting `shade.io.netty.allocator.type=unpooled` to make Netty not use `PoolThreadCache`.

## Tags - issue 3

TiSpark, OOM

## Related material - issue 3

[TiSpark-362](https://internal.pingcap.net/jira/browse/TISPARK-362)

## Added by - issue 3

Liangliang Gu

---------------------------------------------------

## **TiSpark local class incompatible**

---------------------------------------------------

## Affected versions - issue 4

All versions

## Problem Description - issue 4

After upgrading tispark, I encountered a local class incompatible error.

## Solution - issue 4

Check if all the places where tispark jar packages are deployed are using the same jar package (md5), and if they are different, replace them all with the same jar package.

## Cause of the problem - issue 4

The same spark cluster needs to use the same version of the tispark jar package, if it is not the same, it will pack the local class incompatible error.

Since spark has many deployment methods and supports many third-party frameworks, such as zeppelin, the tispark jar package also needs to be deployed to the corresponding framework, and this deployment method is different in different companies. When upgrading tispark, you may forget that the tispark jar packages used in some frameworks are not upgraded at the same time, thus causing this problem.

## Tags - issue 4

TiSpark, upgrade

## Added by - issue 4

Liangliang Gu

---------------------------------------------------

## **TiSpark can't read the View in TiDB**

---------------------------------------------------

## Affected versions - issue 5

All versions

## Problem Description - issue 5

The view created in tidb cannot be viewed with TiSpark show tables command, and the data from tidb view cannot be read with TiSpark.

## Solution - issue 5

Use the spark create view command to manually create the corresponding view in the spark catalog

## Cause of the problem - issue 5

There are a lot of incompatibilities between tidb-sql and spark-sql. If you want to support tidb view in tispark, you need to do a lot of work to implement the logic of tidb-sql, which is very cost effective, so you will not consider supporting it in the foreseeable future.

However, spark-sql itself also supports views, so you can get around this problem by manually creating a corresponding view in the spark catalog via spark-sql syntax. Of course there are incompatibilities between tidb-sql and spark-sql, so when creating the corresponding view, you need to make the corresponding translation changes.

## Tags - issue 5

TiSpark, View

## Related material - issue 5

[Issue #1329](https://github.com/pingcap/tispark/issues/1329)

## Added by - issue 5

Gu Liangliang